pub trait Animation<T>: 'staticwhere
T: Animatable,{
Show 15 methods
// Required methods
fn value(&self) -> &T;
fn state(&self) -> AnimationState;
fn tick(&mut self, delta: Duration);
fn pause(&mut self);
fn resume(&mut self);
fn cancel(&mut self);
fn seek(&mut self, progress: f32);
fn finish(&mut self);
// Provided methods
fn duration(&self) -> Option<Duration> { ... }
fn advance(&mut self, delta: Duration) -> Duration { ... }
fn retarget(&mut self, _target: &T) -> bool { ... }
fn is_active(&self) -> bool { ... }
fn set_rate(&mut self, _rate: f64) { ... }
fn rate(self, rate: f64) -> Self
where Self: Sized { ... }
fn into_value(self: Box<Self>) -> T { ... }
}Expand description
A stateful source that produces animated values over time.
Required Methods§
Sourcefn state(&self) -> AnimationState
fn state(&self) -> AnimationState
Returns the animation’s lifecycle state.
Provided Methods§
Sourcefn advance(&mut self, delta: Duration) -> Duration
fn advance(&mut self, delta: Duration) -> Duration
Advances the animation and returns any unconsumed duration.
Sourcefn retarget(&mut self, _target: &T) -> bool
fn retarget(&mut self, _target: &T) -> bool
Attempts to continue the animation toward a new target.
Returns true when the animation supports retargeting.
Sourcefn set_rate(&mut self, _rate: f64)
fn set_rate(&mut self, _rate: f64)
Updates playback rate by adjusting the animation’s stored durations.
The default implementation does nothing, which is appropriate for animations such as springs that are not duration-based.
Sourcefn rate(self, rate: f64) -> Selfwhere
Self: Sized,
fn rate(self, rate: f64) -> Selfwhere
Self: Sized,
Returns this animation with its playback rate adjusted.
A rate of 2.0 halves duration, while 0.5 doubles it. Repeated calls
compound because implementations update duration directly instead of
storing a separate rate value.
Sourcefn into_value(self: Box<Self>) -> T
fn into_value(self: Box<Self>) -> T
Consumes the animation and returns its current value.
The default implementation clones the sampled value so custom animations remain source-compatible. Implementations that own their sampled value should override this method to move it without cloning.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".