spatial_led 0.3.0

Sled is an ergonomic rust library that maps out the shape of your LED strips in 2D space to help you create stunning lighting effects.
Documentation
use core::ops::AddAssign;
use core::ops::SubAssign;
use core::time::Duration;

/// A trait to abstract a temporal instant
///
/// Instants are monotonically increasing.
pub trait Instant: Clone + Copy + SubAssign<Duration> + AddAssign<Duration> {
    /// Return the current instant
    fn now() -> Self;

    /// Compute the duration since this instant
    fn elapsed(&self) -> core::time::Duration;
}

/// A trait to abstract a sleep function
pub trait Sleeper {
    /// Sleep for the specified duration
    fn sleep(&mut self, duration: core::time::Duration);
}

/// A trait to abstract an asynchronous sleep function
pub trait AsyncSleeper {
    /// Sleep for the specified duration
    #[allow(async_fn_in_trait)]
    async fn sleep(&mut self, duration: core::time::Duration);
}

#[cfg(feature = "std")]
impl Instant for std::time::Instant {
    fn now() -> Self {
        std::time::Instant::now()
    }

    fn elapsed(&self) -> core::time::Duration {
        self.elapsed()
    }
}

/// A sleeper that calls `std::thread::sleep()`
#[cfg(feature = "std")]
#[derive(Default)]
pub struct StdSleeper;

#[cfg(feature = "std")]
impl Sleeper for StdSleeper {
    fn sleep(&mut self, duration: core::time::Duration) {
        std::thread::sleep(duration)
    }
}

/// A sleeper that calls `spin_sleep::sleep()`
#[cfg(feature = "spin_sleep")]
#[derive(Default)]
pub struct SpinSleeper;

#[cfg(feature = "spin_sleep")]
impl Sleeper for SpinSleeper {
    fn sleep(&mut self, duration: core::time::Duration) {
        spin_sleep::sleep(duration)
    }
}