use std::cmp::Ordering; /// Helper struct to associate an item with its priority #[derive(Debug, Clone, Copy)] pub struct Item { data: D, priority: P, } impl Item { /// Creates a new instance fn new(data: D, priority: P) -> Self { Self { data, priority } } /// Retrieve the internal data, it would be nicer to implement this using [`From`] or [`Into`], but I don't see a way to do that using generics fn data(self) -> D { self.data } } // The relevant Ord implementations are based just on the priority impl Ord for Item { fn cmp(&self, other: &Self) -> Ordering { self.priority.cmp(&other.priority) } } impl PartialOrd for Item { fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } impl PartialEq for Item { fn eq(&self, other: &Self) -> bool { self.priority == other.priority } } impl Eq for Item {}