any_cmp
Support dynamic type comparisons.
The author of this crate is not good at English.
Forgive me if the document is hard to read.
What is this?
This crate provides traits that are comparable and can be dynamic types.
Mainly includes the following items.
AnyEq- Likestd::cmp::Eq.AnyHash- Likestd::hash::Hash.AnyOrd- Likestd::cmp::Ord.AnyPartialEq- Likestd::cmp::PartialEq.AnyPartialOrd- Likestd::cmp::PartialOrd.ObjHash- Trait that combinesAnyEqandAnyHash.
Examples
Here is an example simple but useless.
let x = &42 as &dyn AnyEq;
let y = &42 as &dyn AnyEq;
let z = &"42" as &dyn AnyEq;
assert!;
assert!;
Here is an example of using dynamic types for HashMap keys.
let mut map = new;
map.insert;
map.insert;
map.insert;
assert_eq!;
assert_eq!;
assert_eq!;
What's New
v0.4.0
- Fix forgotten implementation.
- Add box upcasting methods (ex:
as_any_eq_box).
v0.3.0
must_useannotations are added at several locations.
v0.2.0
- Module
upcastspecs have slightly changed.