Arbitrary Ordering
Provides a wrapper for types that can technically implement PartialOrd
/Ord
but for semantic reasons it is nonsensical.
Examples
You might want to use a type as a key in a BTreeMap
, this requires Ord
even though it might be
nonsensical to implement a total order for the type.
use Ordering;
use BTreeMap;
use ;
/// A Foo type.
///
/// We do not want users to be able to write `a < b` because it is meaningless
/// to compare the two but we wish to use `Foo`, for example, as a `BTreeMap` key.
let a = Space;
let b = Time;
let mut map = new;
// error[E0277]: the trait bound `Foo: Ord` is not satisfied
// map.insert(a, "some interesting value");
map.insert;
map.insert;
Perhaps you would like to derive Ord
on a complex type that contains a type that does not
implement Ord
.
/// An example struct that contains a `Foo` but derives `PartialOrd` and `Ord`.
// Then there are various ways to get at the inner data.
let adt = Adt ;
println!;
println!;
println!;
// And if all that is too complicated just use the inherent methods:
println!;
println!;
Minimum Supported Rust Version (MSRV)
The crate MSRV is Rust v1.56.1
Licensing
The code in this project is licensed under the Creative Commons CC0 1.0 Universal license. We use the SPDX license list and SPDX IDs.