From your example it looks like you don't want preserved order of adding, but completely ordered taking into account the inner priority value?
You're getting mixed results, because you don't compare the numbers in your Ord impl:
match *self {
WithPriority::Low(_) => Ordering::Less,
WithPriority::High(_) => Ordering::Greater,
}
Instead of _ you should read the value and compare it, too.
And to preserve adding order on top of that, you could insert (WithPriority, usize) to the heap, where the second number is an internal counter you increase every time you add an item.
In my example, u32 was added just to manually mark order of pushed values. For my real code I need something more complex: priority queue for items like
where ordering makes sense only for priority value, but not for item itself. And I want to preserve order of adding for items with same priority.
I thought about just adding monotonically increasing counter into the WithPriority struct. But this does not seem to be the right solution because counter will eventually overflow.