Skip to main content

DataSystem

Trait DataSystem 

Source
pub trait DataSystem:
    Clone
    + Debug
    + PartialEq
    + Eq
    + Hash
    + Send
    + Sync
    + 'static {
    type Animated: AnimatedDataSystem<Data = Self>;
    type DataType: Clone + Copy + Debug + PartialEq + Eq + Hash + Send + Sync;

    // Required methods
    fn discriminant(&self) -> Self::DataType;
    fn variant_name(&self) -> &'static str;

    // Provided methods
    fn try_len(&self) -> Option<usize> { ... }
    fn pad_to_length(&mut self, _target_len: usize) { ... }
}
Expand description

A complete data type system.

This trait defines the contract for a “data enum” – a type that can hold any of several different value types (scalars, vectors, matrices, etc.).

The built-in Data type implements this trait. You can define your own enums and implement this trait to create custom type systems.

§Associated Types

  • Animated – The corresponding animated data container type.
  • DataType – A discriminant enum for identifying variants.

§Example

impl DataSystem for MyData {
    type Animated = MyAnimatedData;
    type DataType = MyDataType;

    fn data_type(&self) -> MyDataType {
        match self {
            MyData::Float(_) => MyDataType::Float,
            MyData::Quat(_) => MyDataType::Quat,
        }
    }

    fn type_name(&self) -> &'static str {
        match self {
            MyData::Float(_) => "float",
            MyData::Quat(_) => "quat",
        }
    }
}

Required Associated Types§

Source

type Animated: AnimatedDataSystem<Data = Self>

The animated data container type for this system.

Source

type DataType: Clone + Copy + Debug + PartialEq + Eq + Hash + Send + Sync

The discriminant type for identifying variants.

Required Methods§

Source

fn discriminant(&self) -> Self::DataType

Returns the discriminant for this value.

Named discriminant() to avoid conflict with DataTypeOps::data_type().

Source

fn variant_name(&self) -> &'static str

Returns a human-readable type name for this value.

Named variant_name() to avoid conflict with DataTypeOps::type_name().

Provided Methods§

Source

fn try_len(&self) -> Option<usize>

Returns the length if this is a vector type, None for scalars.

Override this for data systems that support vector types.

Source

fn pad_to_length(&mut self, _target_len: usize)

Pads a vector value to the target length.

Override this for data systems that support vector types. Does nothing by default.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§