Nested sets and conversions between them (using an injective mapping). Useful to work with
substructures. In generic code, it is preferable to use
SupersetOf as trait bound whenever
possible instead of
SubsetOf (because SupersetOf is automatically implemented whenever
The notion of "nested sets" is very broad and applies to what the types are supposed to represent, independently from their actual implementation details and limitations. For example:
- f32 and f64 are both supposed to represent reals and are thus considered equal (even if in practice f64 has more elements).
- u32 and i8 are respectively supposed to represent natural and relative numbers. Thus, u32 is a subset of i8.
- A quaternion and a 3x3 orthogonal matrix with unit determinant are both sets of rotations. They can thus be considered equal.
In other words, implementation details due to machine limitations are ignored (otherwise we could not even, e.g., convert a u64 to an i64). If considering those limitations are important, other crates allowing you to query the limitations of given types should be used.
fn to_superset(&self) -> T
The inclusion map: converts
self to the equivalent element of its superset.
unsafe fn from_superset_unchecked(element: &T) -> Self
Use with care! Same as
self.to_superset but without any property checks. Always succeeds.
fn is_in_subset(element: &T) -> bool
element is actually part of the subset
Self (and can be converted to it).
fn from_superset(element: &T) -> Option<Self>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
element has no equivalent in