macro_rules! define_data_types {
(
$(#[$meta:meta])*
$vis:vis $data_name:ident / $animated_name:ident / $discriminant_name:ident {
$(
$(#[$variant_meta:meta])*
$variant:ident($inner_ty:ty)
),+ $(,)?
}
) => { ... };
}Expand description
Define a custom data type system with full interpolation support.
This macro generates three enums and implements all necessary traits
for use with GenericValue and
GenericTokenValueMap:
- A discriminant enum (like
DataType) with unit variants. - A data enum (like
Data) holding actual values. - An animated data enum (like
AnimatedData) holdingTimeDataMap<T>values.
§Example
ⓘ
use token_value_map::{define_data_types, TimeDataMap, Time, DataSystem};
define_data_types! {
/// My custom data types.
#[derive(Clone, Debug, PartialEq)]
pub MyData / MyAnimatedData / MyDataType {
/// A floating point value.
Float(MyFloat),
/// An integer value.
Int(MyInt),
}
}
// Now you can use GenericValue<MyData> and GenericTokenValueMap<MyData>.
use token_value_map::GenericValue;
let uniform = GenericValue::<MyData>::uniform(MyData::Float(MyFloat(42.0)));
let animated = GenericValue::<MyData>::animated(vec![
(Time::default(), MyData::Float(MyFloat(0.0))),
(Time::from(10.0), MyData::Float(MyFloat(100.0))),
]).unwrap();§Generated Types
Given MyData / MyAnimatedData / MyDataType:
MyDataType: Discriminant enum with unit variants (Float,Int,Text).MyData: Data enum holding values (Float(f32),Int(i32),Text(String)).MyAnimatedData: Animated enum holding time maps (Float(TimeDataMap<f32>), etc.).
§Requirements
Each variant type must implement:
Clone + Debug + PartialEq + Eq + Hash + Send + Sync + 'static
For interpolation support, types should also implement:
Add<Output = Self> + Sub<Output = Self>Mul<f32, Output = Self> + Mul<f64, Output = Self>Div<f32, Output = Self> + Div<f64, Output = Self>
Types that don’t support interpolation will use sample-and-hold behavior.