use crate::core::{Pos, Rect};
use pxlfmt::pixel::{Format, Pixel};
pub trait DrawTarget {
type Format: Format;
type Error;
fn draw_pixel(&mut self, pos: Pos, color: Pixel<Self::Format>) -> Result<(), Self::Error>;
fn fill_rect(&mut self, rect: Rect, color: Pixel<Self::Format>) -> Result<(), Self::Error> {
let mut pixels = rect.into_iter_row_major();
pixels.try_for_each(|pos| self.draw_pixel(pos, color))?;
Ok(())
}
fn fill_rect_iter(
&mut self,
rect: Rect,
pixels: impl IntoIterator<Item = Pixel<Self::Format>>,
) -> Result<(), Self::Error> {
rect.into_iter_row_major()
.zip(pixels)
.try_for_each(|(pos, color)| self.draw_pixel(pos, color))?;
Ok(())
}
}