pub trait Sort<Other = Self>where
Other: ?Sized,{
// Required method
fn compare(&self, other: &Other) -> Ordering;
}
Expand description
Provides a comparison between Self
and Other
.
This function should only be implemented for types who guarantee that their
PartialOrd<Other>
implementations are identical to their PartialOrd
implementations. For example, Path
and PathBuf
can be interchangeably
compared regardless of whether the left or right or both are a Path
or
PathBuf
.
Why not just use PartialOrd<Other>
? Unfortunately, PartialOrd<str>
is
not implemented for
String
. This led to
issues implementing the Map::entry
function when passing a &str
when the Key
type was String
.
This trait is automatically implemented for types that implement Ord
and
PartialOrd<Other>
, but it additionally provides implementations for
String
/str
and Vec<T>
/[T]
.
In general, this trait should not need to be implemented. Implement
Ord
on your Key
type, and if needed, implement PartialOrd<Other>
for
your borrowed form.