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 } } /// Retrieves 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. pub fn data(self) -> D { self.data } } 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 } }