pub trait TryStableInterpolate: Clone {
type Error;
// Required method
fn try_interpolate_stable(
&self,
other: &Self,
t: f32,
) -> Result<Self, Self::Error>;
}Expand description
A trait that indicates that a value may be interpolable via StableInterpolate. An
interpolation may fail if the values have different units - for example, attempting to
interpolate between Val::Px and Val::Percent will fail,
even though they are the same Rust type.
Fallible interpolation can be used for animated transitions, which can be set up to fail
gracefully if the the values cannot be interpolated. For example, the a transition could smoothly
go from Val::Px(10) to Val::Px(20), but if the user attempts to go from Val::Px(10) to
Val::Percent(10), the animation player can detect the failure and simply snap to the new
value without interpolating.
An animation clip system can incorporate fallible interpolation to support a broad set of sequenced parameter values. This can include numeric types, which always interpolate, enum types, which may or may not interpolate depending on the units, and non-interpolable types, which always jump immediately to the new value without interpolation. This meaas, for example, that you can have an animation track whose value type is a boolean or a string.
Interpolation for simple number and coordinate types will always succeed, as will any type
that implements StableInterpolate. Types which have different variants such as
Val and Color will only fail if the units are different.
Note that Color has its own, non-fallible mixing methods, but those entail
automatically converting between different color spaces, and is both expensive and complex.
TryStableInterpolate is more conservative, and doesn’t automatically convert between
color spaces. This produces a color interpolation that has more predictable performance.
Required Associated Types§
Required Methods§
Sourcefn try_interpolate_stable(
&self,
other: &Self,
t: f32,
) -> Result<Self, Self::Error>
fn try_interpolate_stable( &self, other: &Self, t: f32, ) -> Result<Self, Self::Error>
Attempt to interpolate the value. This may fail if the two interpolation values have different units, or if the type is not interpolable.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.