You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What is the use case? I tried to think it through for Vec but I got to this code that builds already.
/// A point in 2D space.////// We do not want users to be able to write `a < b` because it is not well defined.#[derive(Debug,Clone,Copy,PartialEq,Eq,Hash)]structPoint{x:u32,y:u32,}implArbitraryOrdforPoint{fnarbitrary_cmp(&self,other:&Self) -> Ordering{(self.x,self.y).cmp(&(other.x, other.y))}}impl fmt::DisplayforPoint{fnfmt(&self,f:&mut fmt::Formatter) -> fmt::Result{write!(f,"({}, {})",self.x,self.y)}}/// A type that derives `Ord` and friends.#[derive(Debug,Clone,PartialEq,Eq,PartialOrd,Ord,Hash)]structAdt{// point: Point, // Doesn't build, this is the reason we provide `Ordered`.point:Ordered<Point>,// v: Vec<Point>, // Also doesn't build but we can wrap in `Ordered` again.v:Vec<Ordered<Point>>,}
The use case is being able to write things like BTreeMap<Ordered<Box<HugeStructWithArbitrarryOrd>>> etc. Generally, crates implement their traits for all sensible std types. For Vec, dealing with Ordered<Vec<Point>> is very likely less annoying than Vec<Ordered<Point>.
Box
Rc
Arc
[T]
Vec
Option
Result
ManuallyDrop
Basically anything that has
Ord
already.The text was updated successfully, but these errors were encountered: