From 5118fbcc0618dadcb82247a7fedcdcb383fc4c96 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Mon, 7 Oct 2024 17:46:52 +1300 Subject: Implement as_mut_rows for Buffer This is to match the existing immutable as_rows method. --- src/lib.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index abcd80f..99c9529 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,7 +2,7 @@ pub use colour::Colour; pub use geometry::HasDimensions; use std::ops::{Deref, DerefMut, Index, IndexMut}; -use std::slice::SliceIndex; +use std::slice::{ChunksExact, ChunksExactMut, SliceIndex}; pub type Point = geometry::Point; pub type Dimensions = geometry::Dimensions; @@ -61,10 +61,13 @@ impl Buffer { self.dimensions = dimensions; } - pub fn as_rows(&self) -> std::slice::ChunksExact { + pub fn as_rows(&self) -> ChunksExact { self.pixels.chunks_exact(self.dimensions.width as usize) } + pub fn as_mut_rows(&mut self) -> ChunksExactMut { + self.pixels.chunks_exact_mut(self.dimensions.width as usize) + } pub fn as_u32_slice(&self) -> &[u32] { unsafe { std::mem::transmute::<&[Colour], &[u32]>(&self.pixels) } -- cgit v1.2.3-70-g09d2