How can I implement Ord when the comparison depends on data not part of the compared items?
问题 I have a small struct containing only an i32 : struct MyStruct { value: i32, } I want to implement Ord in order to store MyStruct in a BTreeMap or any other data structure that requires you to have Ord on its elements. In my case, comparing two instances of MyStruct does not depend on the value s in them, but asking another data structure (a dictionary), and that data structure is unique for each instance of the BTreeMap I will create. So ideally it would look like this: impl Ord for MyStruct