use std::cmp::Ordering; /// Container to associate an item with a priority #[derive(Debug, Clone, Copy)] pub struct Pair { data: D, priority: P, } impl Pair { /// Creates a new instance pub fn new(data: D, priority: P) -> Self { Self { data, priority } } /// Returns the internal data. /// It might(?) be nicer to implement this using [`From`] or [`Into`], but I don't see a way to do that using generics. pub fn data(self) -> D { self.data } pub fn get_data(&self) -> &D { &self.data } /// Retrieve the priority associated with the data pub fn get_priority(&self) -> &P { &self.priority } /// Update the priority associated with the data pub fn set_priority(&mut self, priority: P) { self.priority = priority } } impl PartialOrd for Pair { fn partial_cmp(&self, other: &Self) -> Option { self.priority.partial_cmp(&other.priority) } } impl PartialEq for Pair { fn eq(&self, other: &Self) -> bool { self.priority == other.priority } }