Skip to content

Commit

Permalink
Impl Interpolator for Arc<I>, Arc<Mutex<I>> and Arc<RwLock<I>>
Browse files Browse the repository at this point in the history
  • Loading branch information
Multirious committed Mar 26, 2024
1 parent dc0abd7 commit 7aa8805
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion src/interpolate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
//! If you've created a custom interpolator or a custom component/asset/resource,
//! you may need to [register some systems](crate::tween#registering-systems).

use std::sync::{Arc, Mutex, RwLock};

use bevy::prelude::*;

#[cfg(feature = "bevy_sprite")]
Expand Down Expand Up @@ -145,7 +147,38 @@ where
}
}

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

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

impl<I> Interpolator for Arc<Mutex<I>>
where
I: Interpolator + ?Sized,
{
type Item = I::Item;

fn interpolate(&self, item: &mut Self::Item, value: f32) {
self.lock().expect("valid Mutex").interpolate(item, value)
}
}

impl<I> Interpolator for Arc<RwLock<I>>
where
I: Interpolator,
{
type Item = I::Item;

fn interpolate(&self, item: &mut Self::Item, value: f32) {
self.read().expect("valid RwLock").interpolate(item, value)
}
}

/// Default interpolators
pub struct DefaultInterpolatorsPlugin;
Expand Down

0 comments on commit 7aa8805

Please sign in to comment.