Skip to main content

GenericValue

Enum GenericValue 

Source
pub enum GenericValue<D: DataSystem> {
    Uniform(D),
    Animated(D::Animated),
}
Expand description

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

This is the generic version of Value that works with any DataSystem. Use this when you have a custom data type system.

For the built-in types, use Value which is an alias for GenericValue<Data>.

Variants§

§

Uniform(D)

A constant value that does not change over time.

§

Animated(D::Animated)

A value that changes over time with keyframe interpolation.

Implementations§

Source§

impl<D: DataSystem> GenericValue<D>

Source

pub fn uniform(value: D) -> Self

Creates a uniform value that does not change over time.

Source

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

Creates 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(&mut self, time: Time, value: D) -> Result<()>

Adds a sample at a specific time.

If the value is uniform, it becomes animated with the new sample.

Source

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

Removes 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<D>

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 GenericValue::Animated to GenericValue::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<D>

Samples the value at an 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 interpolate(&self, time: Time) -> D

Interpolates the value at the given time.

For uniform values, returns the constant value. For animated values, interpolates between surrounding keyframes.

Source

pub fn is_animated(&self) -> bool

Returns true if the value is animated (has multiple keyframes).

Source

pub fn sample_count(&self) -> usize

Returns the number of time samples.

Source

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

Returns all keyframe times.

Source

pub fn discriminant(&self) -> D::DataType

Returns the data type discriminant for this value.

Source

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

Returns a human-readable type name for this value.

Source

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

Merges 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.

Source

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

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

For animated values, samples at standardized points within the shutter range and hashes the interpolated values.

Trait Implementations§

Source§

impl<D: Clone + DataSystem> Clone for GenericValue<D>
where D::Animated: Clone,

Source§

fn clone(&self) -> GenericValue<D>

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<D: Debug + DataSystem> Debug for GenericValue<D>
where D::Animated: Debug,

Source§

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

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

impl<D: DataSystem> From<D> for GenericValue<D>

Source§

fn from(value: D) -> Self

Converts to this type from the input type.
Source§

impl<D: Hash + DataSystem> Hash for GenericValue<D>
where D::Animated: Hash,

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<D: PartialEq + DataSystem> PartialEq for GenericValue<D>
where D::Animated: PartialEq,

Source§

fn eq(&self, other: &GenericValue<D>) -> 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<D: DataSystem> Eq for GenericValue<D>

Source§

impl<D: DataSystem> StructuralPartialEq for GenericValue<D>

Auto Trait Implementations§

§

impl<D> Freeze for GenericValue<D>
where D: Freeze, <D as DataSystem>::Animated: Freeze,

§

impl<D> RefUnwindSafe for GenericValue<D>

§

impl<D> Send for GenericValue<D>

§

impl<D> Sync for GenericValue<D>

§

impl<D> Unpin for GenericValue<D>
where D: Unpin, <D as DataSystem>::Animated: Unpin,

§

impl<D> UnsafeUnpin for GenericValue<D>

§

impl<D> UnwindSafe for GenericValue<D>

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.