pub struct GridBuf<T, B, L> { /* private fields */ }buffer only.Expand description
Implementations§
Source§impl<T, B, L> GridBuf<T, B, L>
impl<T, B, L> GridBuf<T, B, L>
Sourcepub fn from_buffer(buffer: B, width: usize) -> Self
pub fn from_buffer(buffer: B, width: usize) -> Self
Returns a grid from an existing buffer with a given width in columns.
The height is inferred from the buffer length and width.
Any data type that can be represented as a slice can be used as the buffer type, including arrays, slices, and vectors.
§Panics
This panics if the buffer length is not a multiple of the width.
§Example
use grixy::prelude::*;
let buffer = vec![1, 2, 3, 4, 5, 6];
let grid = GridBuf::<_, _, RowMajor>::from_buffer(buffer, 3);
assert_eq!(grid.get(Pos::new(0, 0)), Some(&1));
assert_eq!(grid.get(Pos::new(1, 0)), Some(&2));
assert_eq!(grid.get(Pos::new(2, 1)), Some(&6));
assert_eq!(grid.get(Pos::new(3, 1)), None); // Out of boundsSource§impl<T> GridBuf<T, Vec<T>, RowMajor>
impl<T> GridBuf<T, Vec<T>, RowMajor>
Sourcepub fn new(width: usize, height: usize) -> Self
Available on crate feature alloc only.
pub fn new(width: usize, height: usize) -> Self
alloc only.Creates a new grid with the specified width and height, filled with a default value.
This creates a grid with a row-major layout; see new_filled_with_layout to customize.
§Example
use grixy::prelude::*;
let grid = GridBuf::<u8, _, _>::new(3, 3);
assert_eq!(grid.get(Pos::new(0, 0)), Some(&0));
assert_eq!(grid.get(Pos::new(2, 2)), Some(&0));
assert_eq!(grid.get(Pos::new(3, 3)), None); // Out of boundsSourcepub fn new_filled(width: usize, height: usize, value: T) -> Selfwhere
T: Copy,
Available on crate feature alloc only.
pub fn new_filled(width: usize, height: usize, value: T) -> Selfwhere
T: Copy,
alloc only.Creates a new grid with the specified width and height, filled with a specified value.
This creates a grid with a row-major layout; see new_filled_with_layout to customize.
§Example
use grixy::prelude::*;
let grid = GridBuf::new_filled(5, 4, 42);
assert_eq!(grid.get(Pos::new(0, 0)), Some(&42));
assert_eq!(grid.get(Pos::new(4, 3)), Some(&42));
assert_eq!(grid.get(Pos::new(5, 3)), None); // Out of boundsSource§impl<T, L> GridBuf<T, Vec<T>, L>where
L: LinearLayout,
impl<T, L> GridBuf<T, Vec<T>, L>where
L: LinearLayout,
Sourcepub fn new_filled_with_layout(width: usize, height: usize, value: T) -> Selfwhere
T: Copy,
L: LinearLayout,
Available on crate feature alloc only.
pub fn new_filled_with_layout(width: usize, height: usize, value: T) -> Selfwhere
T: Copy,
L: LinearLayout,
alloc only.Creates a new grid with the specified width and height, filled with a default value.
The layout is specified by the type parameter L, allowing for different memory layouts.
§Example
Source§impl<T, L> GridBuf<T, Vec<T>, L>
impl<T, L> GridBuf<T, Vec<T>, L>
Sourcepub fn resize(&mut self, new_width: usize, new_height: usize)
Available on crate feature alloc only.
pub fn resize(&mut self, new_width: usize, new_height: usize)
alloc only.Resizes the grid to the new dimensions.
Content in the overlap between the old and new dimensions is preserved.
New cells are initialized to T::default().
If both dimensions shrink, excess cells are dropped.
§Examples
use grixy::prelude::*;
let mut grid = GridBuf::new_filled(4, 4, 1u8);
grid[Pos::new(0, 0)] = 99;
grid.resize(6, 6);
assert_eq!(grid.get(Pos::new(0, 0)), Some(&99)); // preserved
assert_eq!(grid.get(Pos::new(5, 5)), Some(&0)); // new, defaultSourcepub fn resize_filled(&mut self, new_width: usize, new_height: usize, value: T)
Available on crate feature alloc only.
pub fn resize_filled(&mut self, new_width: usize, new_height: usize, value: T)
alloc only.Resizes the grid, filling new cells with value instead of Default.
§Examples
use grixy::prelude::*;
let mut grid = GridBuf::new_filled(2, 2, 1u8);
grid.resize_filled(4, 4, 42);
assert_eq!(grid.get(Pos::new(0, 0)), Some(&1)); // preserved
assert_eq!(grid.get(Pos::new(3, 3)), Some(&42)); // new, filled with 42Source§impl<T, B, L> GridBuf<T, B, L>where
L: LinearLayout,
impl<T, B, L> GridBuf<T, B, L>where
L: LinearLayout,
Trait Implementations§
Source§impl<'de, T, L> Deserialize<'de> for GridBuf<T, Vec<T>, L>
Available on crate feature serde only.
impl<'de, T, L> Deserialize<'de> for GridBuf<T, Vec<T>, L>
serde only.Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
impl<T: Eq, B: Eq, L: Eq> Eq for GridBuf<T, B, L>
Source§impl<T, B, L> ExactSizeGrid for GridBuf<T, B, L>where
L: LinearLayout,
impl<T, B, L> ExactSizeGrid for GridBuf<T, B, L>where
L: LinearLayout,
Source§impl<T, B, L> GridBase for GridBuf<T, B, L>where
L: LinearLayout,
impl<T, B, L> GridBase for GridBuf<T, B, L>where
L: LinearLayout,
Source§impl<T, B, L> GridReadUnchecked for GridBuf<T, B, L>
impl<T, B, L> GridReadUnchecked for GridBuf<T, B, L>
Source§impl<T, B, L> GridWriteUnchecked for GridBuf<T, B, L>
impl<T, B, L> GridWriteUnchecked for GridBuf<T, B, L>
Source§unsafe fn set_unchecked(&mut self, pos: Pos, value: Self::Element)
unsafe fn set_unchecked(&mut self, pos: Pos, value: Self::Element)
Source§unsafe fn fill_rect_iter_unchecked(
&mut self,
bounds: Rect,
iter: impl IntoIterator<Item = Self::Element>,
)
unsafe fn fill_rect_iter_unchecked( &mut self, bounds: Rect, iter: impl IntoIterator<Item = Self::Element>, )
impl<T: PartialEq, B: PartialEq, L: PartialEq> StructuralPartialEq for GridBuf<T, B, L>
impl<T, B, L> TrustedSizeGrid for GridBuf<T, B, L>where
L: LinearLayout,
Auto Trait Implementations§
impl<T, B, L> Freeze for GridBuf<T, B, L>where
B: Freeze,
impl<T, B, L> RefUnwindSafe for GridBuf<T, B, L>
impl<T, B, L> Send for GridBuf<T, B, L>
impl<T, B, L> Sync for GridBuf<T, B, L>
impl<T, B, L> Unpin for GridBuf<T, B, L>
impl<T, B, L> UnsafeUnpin for GridBuf<T, B, L>where
B: UnsafeUnpin,
impl<T, B, L> UnwindSafe for GridBuf<T, B, L>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> GridConvertExt for Twhere
T: GridRead,
impl<T> GridConvertExt for Twhere
T: GridRead,
Source§fn copied<'a, T>(self) -> Copied<T, Self>
fn copied<'a, T>(self) -> Copied<T, Self>
Source§fn map<F, T>(self, map_fn: F) -> Mapped<F, Self, T>
fn map<F, T>(self, map_fn: F) -> Mapped<F, Self, T>
Source§fn view(self, bounds: Rect) -> Viewed<Self>where
Self: Sized,
fn view(self, bounds: Rect) -> Viewed<Self>where
Self: Sized,
Source§fn scale(self, factor: usize) -> Scaled<Self>where
Self: Sized,
fn scale(self, factor: usize) -> Scaled<Self>where
Self: Sized,
Source§fn flatten<'a, B, L>(&'a self) -> GridBuf<Self::Element<'a>, B, L>where
B: FromIterator<Self::Element<'a>> + AsRef<[Self::Element<'a>]>,
L: LinearLayout,
Self: Sized + ExactSizeGrid,
Self::Element<'a>: Copy,
fn flatten<'a, B, L>(&'a self) -> GridBuf<Self::Element<'a>, B, L>where
B: FromIterator<Self::Element<'a>> + AsRef<[Self::Element<'a>]>,
L: LinearLayout,
Self: Sized + ExactSizeGrid,
Self::Element<'a>: Copy,
buffer only.