Skip to main content

Animation

Trait Animation 

Source
pub trait Animation<Value>: Send + Sync {
    // Required method
    fn sample(&self, time: Time) -> Value;

    // Provided methods
    fn duration(&self) -> Option<Duration> { ... }
    fn map<Output, Function>(
        self,
        function: Function,
    ) -> Map<Self, Function, Value>
       where Self: Sized,
             Function: Fn(Value) -> Output + Send + Sync { ... }
    fn zip<OtherValue, Other>(self, other: Other) -> Zip<Self, Other>
       where Self: Sized,
             Other: Animation<OtherValue> { ... }
    fn delay(self, offset: Duration) -> Delay<Self>
       where Self: Sized { ... }
    fn speed(self, factor: f64) -> Speed<Self>
       where Self: Sized { ... }
    fn then<Next: Animation<Value>>(self, next: Next) -> Then<Self, Next>
       where Self: Sized { ... }
    fn reverse(self) -> Reverse<Self>
       where Self: Sized { ... }
    fn repeat(self, count: u32) -> Repeat<Self>
       where Self: Sized { ... }
    fn ping_pong(self) -> PingPong<Self>
       where Self: Sized { ... }
    fn boxed(self) -> Arc<dyn Animation<Value>> ⓘ
       where Self: Sized + 'static { ... }
}
Expand description

A thread-safe, randomly addressable animation of values.

Finite implementations hold their endpoint values outside [0, duration]. Infinite implementations may use negative time. Sampling must not depend on earlier calls. A reported duration must be nonnegative and stable.

Required Methods§

Source

fn sample(&self, time: Time) -> Value

Samples without advancing a clock or changing playback state.

Provided Methods§

Source

fn duration(&self) -> Option<Duration>

Returns the finite duration, or None for an unbounded signal.

Source

fn map<Output, Function>(self, function: Function) -> Map<Self, Function, Value>
where Self: Sized, Function: Fn(Value) -> Output + Send + Sync,

Transforms values without changing timing.

Source

fn zip<OtherValue, Other>(self, other: Other) -> Zip<Self, Other>
where Self: Sized, Other: Animation<OtherValue>,

Samples in parallel; the duration is infinite if either input is infinite.

Source

fn delay(self, offset: Duration) -> Delay<Self>
where Self: Sized,

Delays a finite animation, holding its initial value before the offset. Infinite signals shift their signed time instead. Negative offsets and finite duration overflow panic at construction.

Source

fn speed(self, factor: f64) -> Speed<Self>
where Self: Sized,

Changes playback speed by a finite, strictly positive factor. Durations round to the nearest tick; a collapsed finite animation becomes instantaneous. Invalid factors and unrepresentable durations panic.

Source

fn then<Next: Animation<Value>>(self, next: Next) -> Then<Self, Next>
where Self: Sized,

Runs two finite animations in sequence. The second owns their shared boundary. Infinite sources or duration overflow panic at construction.

Source

fn reverse(self) -> Reverse<Self>
where Self: Sized,

Reverses a finite animation. Infinite sources panic at construction.

Source

fn repeat(self, count: u32) -> Repeat<Self>
where Self: Sized,

Plays a finite animation count times. Intermediate boundaries restart; the final boundary holds the target. Zero repeats hold the initial value. Infinite sources or duration overflow panic at construction.

Source

fn ping_pong(self) -> PingPong<Self>
where Self: Sized,

Plays a finite animation forward then backward, ending at its initial value. Infinite sources or duration overflow panic at construction.

Source

fn boxed(self) -> Arc<dyn Animation<Value>> ⓘ
where Self: Sized + 'static,

Shares a type-erased animation, retaining sampling and combinators.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<Value> Animation<Value> for Arc<dyn Animation<Value> + '_>

Source§

fn sample(&self, time: Time) -> Value

Source§

fn duration(&self) -> Option<Duration>

Implementors§

Source§

impl Animation<PathSample> for FollowPath

Source§

impl Animation<f64> for Noise

Source§

impl Animation<f64> for Oscillator

Source§

impl<FirstValue, SecondValue, First, Second> Animation<(FirstValue, SecondValue)> for Zip<First, Second>
where First: Animation<FirstValue>, Second: Animation<SecondValue>,

Source§

impl<Input, Output, Source, Function> Animation<Output> for Map<Source, Function, Input>
where Source: Animation<Input>, Function: Fn(Input) -> Output + Send + Sync,

Source§

impl<Value, First: Animation<Value>, Next: Animation<Value>> Animation<Value> for Then<First, Next>

Source§

impl<Value, Function> Animation<Value> for Function
where Function: Fn(Time) -> Value + Send + Sync,

Source§

impl<Value, Source: Animation<Value>> Animation<Value> for Delay<Source>

Source§

impl<Value, Source: Animation<Value>> Animation<Value> for PingPong<Source>

Source§

impl<Value, Source: Animation<Value>> Animation<Value> for Repeat<Source>

Source§

impl<Value, Source: Animation<Value>> Animation<Value> for Reverse<Source>

Source§

impl<Value, Source: Animation<Value>> Animation<Value> for Speed<Source>

Source§

impl<Value: Clone + Send + Sync> Animation<Value> for Constant<Value>

Source§

impl<Value: Interpolate + Send + Sync> Animation<Value> for Keyframes<Value>

Source§

impl<Value: Interpolate + Send + Sync> Animation<Value> for Spring<Value>

Source§

impl<Value: Interpolate + Send + Sync> Animation<Value> for Tween<Value>