sekineh/binary-heap-plus-rs

Re-export Compare

Opened this issue · 0 comments

First off, thank you for this awesome crate, this is just what I was looking for :)

I'm finding myself needing to implement my own comparator. I have a use case where I have several different KeyComparators, which are all the same except for closing around different values. This means that I have to use BinaryHeap<T, KeyComparator<Box<dyn Fn(&T) -> K>>> as the type for my BinaryHeap since the compiler doesn't know that these different closures are really all the same. This approach makes unnecessary allocations, which can be eliminated if I make it explicit to the compiler that all my closures have the same size and structure. This is just my long winded way of saying I need to make my own comparator struct.

Now the problem I'm facing is importing the Compare trait. It appears that I have to add the compare crate as a dependency to my project in order to do this. This adds problems like ensuring that my crate's version of compare is the version used by my version of binary_heap_plus. I think this is a situation where a crate like binary_heap_plus would typically re-export the trait since it's an important part of your API.

In the meantime I'll just add compare as a dependency, but I'm hoping we can change this soon, if you agree with this change. Thank you for your hard work on this project.