Skip to main content

Value

Enum Value 

Source
pub enum Value {
    Uniform(Data),
    Animated(AnimatedData),
}
Expand description

A value that can be either uniform or animated over time.

A Value contains either a single Data value that remains constant (uniform) or AnimatedData that changes over time with interpolation.

Variants§

§

Uniform(Data)

A constant value that does not change over time.

§

Animated(AnimatedData)

A value that changes over time with keyframe interpolation.

Implementations§

Source§

impl Value

Source

pub fn uniform<V: Into<Data>>(value: V) -> Self

Create a uniform value that does not change over time.

Source

pub fn animated<I, V>(samples: I) -> Result<Self>
where I: IntoIterator<Item = (Time, V)>, V: Into<Data>,

Create an animated value from time-value pairs.

All samples must have the same data type. Vector samples are padded to match the length of the longest vector in the set.

Source

pub fn add_sample<V: Into<Data>>(&mut self, time: Time, val: V) -> Result<()>

Add a sample at a specific time, checking length constraints

Source

pub fn remove_sample(&mut self, time: &Time) -> Option<Data>

Remove a sample at a specific time.

Returns the removed value if it existed. For uniform values, this is a no-op and returns None. The last sample in an animated value cannot be removed (returns None). Use remove_or_make_uniform to degrade to uniform instead.

Source

pub fn remove_or_make_uniform(&mut self, time: &Time) -> Option<Data>

Remove a sample, converting to uniform if it was the last keyframe.

If the value is uniform, returns None. If the removed sample was the last keyframe, the value degrades from Value::Animated to Value::Uniform with that keyframe’s value and returns None (the data is preserved, not lost). Otherwise returns the removed value.

Source

pub fn sample_at(&self, time: Time) -> Option<Data>

Sample value at exact time without interpolation.

Returns the exact value if it exists at the given time, or None if no sample exists at that time for animated values.

Source

pub fn sample_at_or_before(&self, time: Time) -> Option<Data>

Get the value at or before the given time

Source

pub fn sample_at_or_after(&self, time: Time) -> Option<Data>

Get the value at or after the given time

Source

pub fn interpolate(&self, time: Time) -> Data

Interpolate value at the given time.

For uniform values, returns the constant value. For animated values, interpolates between surrounding keyframes using appropriate interpolation methods (linear, quadratic, or hermite).

Source

pub fn sample_surrounding<const N: usize>( &self, time: Time, ) -> SmallVec<[(Time, Data); N]>

Get surrounding samples for interpolation.

Source

pub fn sample_bracket( &self, time: Time, ) -> (Option<(Time, Data)>, Option<(Time, Data)>)

Get the two samples surrounding a time for linear interpolation

Source

pub fn is_animated(&self) -> bool

Check if the value is animated.

Source

pub fn sample_count(&self) -> usize

Get the number of time samples.

Source

pub fn times(&self) -> SmallVec<[Time; 10]>

Get all time samples.

Source

pub fn merge_with<F>(&self, other: &Value, combiner: F) -> Result<Value>
where F: Fn(&Data, &Data) -> Data,

Merge this value with another using a combiner function.

For uniform values, applies the combiner once. For animated values, samples both at the union of all keyframe times and applies the combiner at each time.

§Example
// Multiply two matrices
let result = matrix1.merge_with(&matrix2, |a, b| {
    match (a, b) {
        (Data::Matrix3(m1), Data::Matrix3(m2)) => {
            Data::Matrix3(Matrix3(m1.0 * m2.0))
        }
        _ => a, // fallback
    }
})?;
Source§

impl Value

Source

pub fn hash_with_shutter<H: Hasher>(&self, state: &mut H, shutter: &Shutter)

Hash the value with shutter context for animation-aware caching.

For animated values, this samples at standardized points within the shutter range and hashes the interpolated values rather than raw keyframes. This provides better cache coherency for animations with different absolute times but identical interpolated values.

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Value

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl DataTypeOps for Value

Available on crate feature builtin-types only.
Source§

fn data_type(&self) -> DataType

Returns the DataType variant for this value.
Source§

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

Returns a string name for this data type.
Source§

impl Debug for Value

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<V: Into<Data>> From<V> for Value

Source§

fn from(value: V) -> Self

Converts to this type from the input type.
Source§

impl Hash for Value

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Value

Source§

fn eq(&self, other: &Value) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Sample<Color> for Value

Source§

fn sample( &self, shutter: &Shutter, samples: NonZeroU16, ) -> Result<Vec<(Color, SampleWeight)>>

Generate samples across the shutter interval. Read more
Source§

impl Sample<Integer> for Value

Source§

fn sample( &self, shutter: &Shutter, samples: NonZeroU16, ) -> Result<Vec<(Integer, SampleWeight)>>

Generate samples across the shutter interval. Read more
Source§

impl Sample<Matrix3> for Value

Source§

fn sample( &self, shutter: &Shutter, samples: NonZeroU16, ) -> Result<Vec<(Matrix3, SampleWeight)>>

Generate samples across the shutter interval. Read more
Source§

impl Sample<Real> for Value

Source§

fn sample( &self, shutter: &Shutter, samples: NonZeroU16, ) -> Result<Vec<(Real, SampleWeight)>>

Generate samples across the shutter interval. Read more
Source§

impl Sample<Vector2> for Value

Source§

fn sample( &self, shutter: &Shutter, samples: NonZeroU16, ) -> Result<Vec<(Vector2, SampleWeight)>>

Generate samples across the shutter interval. Read more
Source§

impl TryFrom<&Value> for Boolean

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&Value> for BooleanVec

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&Value> for Color

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&Value> for ColorCurve

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&Value> for ColorVec

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&Value> for Integer

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&Value> for IntegerVec

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&Value> for Matrix3

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&Value> for Matrix3Vec

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&Value> for Real

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&Value> for RealCurve

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&Value> for RealVec

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&Value> for String

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&Value> for StringVec

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&Value> for Vector2

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&Value> for Vector2Vec

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Value> for Boolean

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Value> for BooleanVec

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Value> for Color

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Value> for ColorCurve

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Value> for ColorVec

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Value> for Integer

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Value> for IntegerVec

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Value> for Matrix3

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Value> for Matrix3Vec

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Value> for Real

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Value> for RealCurve

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Value> for RealVec

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Value> for String

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Value> for StringVec

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Value> for Vector2

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Value> for Vector2Vec

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for Value

Source§

impl StructuralPartialEq for Value

Auto Trait Implementations§

§

impl Freeze for Value

§

impl RefUnwindSafe for Value

§

impl Send for Value

§

impl Sync for Value

§

impl Unpin for Value

§

impl UnsafeUnpin for Value

§

impl UnwindSafe for Value

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.