Trait simba::scalar::SupersetOf

source ·
pub trait SupersetOf<T>: Sized {
    // Required methods
    fn is_in_subset(&self) -> bool;
    fn to_subset_unchecked(&self) -> T;
    fn from_subset(element: &T) -> Self;

    // Provided method
    fn to_subset(&self) -> Option<T> { ... }
}
Expand description

Nested sets and conversions between them. Useful to work with substructures. It is preferable to implement the SubsetOf trait instead of SupersetOf whenever possible (because SupersetOf is automatically implemented whenever SubsetOf is).

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, i8 is a superset of u32.
  • 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.

Required Methods§

source

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).

source

fn to_subset_unchecked(&self) -> T

Use with care! Same as self.to_subset but without any property checks. Always succeeds.

source

fn from_subset(element: &T) -> Self

The inclusion map: converts self to the equivalent element of its superset.

Provided Methods§

source

fn to_subset(&self) -> Option<T>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset.

Must return None if element has no equivalent in Self.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<SS: SubsetOf<SP>, SP> SupersetOf<SS> for SP