holiday_lights/lights/src/lib.rs

33 lines
819 B
Rust

#![no_std]
pub mod gamma;
pub mod rgb;
use core::borrow::Borrow;
/// An RGB value in physical color space, which should be passed on to an LED for display.
/// Not suitable for color operations, since its values won't be perceptually linear.
/// See the [rgb] module for the former, and the [gamma] module to convert into this.
#[derive(Clone, Copy)]
pub struct HardwareRgb(pub u8, pub u8, pub u8);
pub trait Lights {
type Pixel;
fn render(&mut self, pixel: &Self::Pixel);
fn latch(&mut self);
}
pub trait PixelIterator<T: Lights> {
fn render_to(&mut self, lights: &mut T);
}
impl<T: Lights, I: Iterator> PixelIterator<T> for I
where I::Item: Borrow<T::Pixel>
{
#[inline]
fn render_to(&mut self, lights: &mut T) {
self.for_each(|pixel| lights.render(pixel.borrow()));
}
}