Skip to content

Commit

Permalink
Improve Interpolator impl for closure
Browse files Browse the repository at this point in the history
  • Loading branch information
Multirious committed Mar 26, 2024
1 parent b877f9e commit f1a262a
Showing 1 changed file with 8 additions and 20 deletions.
28 changes: 8 additions & 20 deletions src/interpolate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,26 +105,6 @@ pub trait Interpolator: Send + Sync + 'static {
fn interpolate(&self, item: &mut Self::Item, value: f32);
}

impl<I: 'static> Interpolator
for Box<dyn Fn(&mut I, f32) + Send + Sync + 'static>
{
type Item = I;

fn interpolate(&self, item: &mut Self::Item, value: f32) {
self(item, value)
}
}

impl<I: 'static> Interpolator
for &'static (dyn Fn(&mut I, f32) + Send + Sync + 'static)
{
type Item = I;

fn interpolate(&self, item: &mut Self::Item, value: f32) {
self(item, value)
}
}

impl<I> Interpolator for Box<I>
where
I: Interpolator + ?Sized,
Expand Down Expand Up @@ -158,6 +138,14 @@ where
}
}

impl<I: 'static> Interpolator for dyn Fn(&mut I, f32) + Send + Sync + 'static {
type Item = I;

fn interpolate(&self, item: &mut Self::Item, value: f32) {
self(item, value)
}
}

/// Default interpolators
pub struct DefaultInterpolatorsPlugin;
impl Plugin for DefaultInterpolatorsPlugin {
Expand Down

0 comments on commit f1a262a

Please sign in to comment.