pub struct ValueGrid<T: Value> { /* private fields */ }Expand description
A 2D grid of values.
The memory layout is the one the display expects in crate::Commands.
This structure can be used with any type that implements the Value trait.
You can also use the concrete type aliases provided in this crate, e.g. crate::CharGrid and crate::ByteGrid.
Implementations§
Source§impl ValueGrid<Brightness>
impl ValueGrid<Brightness>
Sourcepub fn saturating_load(width: usize, height: usize, data: &[u8]) -> Option<Self>
pub fn saturating_load(width: usize, height: usize, data: &[u8]) -> Option<Self>
Like Self::load, but ignoring any out-of-range brightness values
Source§impl ValueGrid<u8>
impl ValueGrid<u8>
Sourcepub fn load_ascii(
value: &str,
width: usize,
wrap: bool,
) -> Result<Self, InvalidCharError>
pub fn load_ascii( value: &str, width: usize, wrap: bool, ) -> Result<Self, InvalidCharError>
Source§impl<T: Value> ValueGrid<T>
impl<T: Value> ValueGrid<T>
Sourcepub fn from_vec(width: usize, data: Vec<T>) -> Option<Self>
pub fn from_vec(width: usize, data: Vec<T>) -> Option<Self>
Creates a ValueGrid with the specified width from the provided data,
wrapping to as many rows as needed,
without copying the vec.
returns: ValueGrid that contains the provided data,
or None if the data size is not divisible by the width.
§Examples
let grid = ValueGrid::from_vec(2, vec![0, 1, 2, 3, 4, 5]).unwrap();Sourcepub fn iter(&self) -> impl Iterator<Item = &T>
pub fn iter(&self) -> impl Iterator<Item = &T>
Iterate over all cells in ValueGrid.
Order is equivalent to the following loop:
for y in 0..grid.height() {
for x in 0..grid.width() {
grid.get(x, y);
}
}Sourcepub fn iter_rows(&self) -> impl Iterator<Item = Iter<'_, T>>
pub fn iter_rows(&self) -> impl Iterator<Item = Iter<'_, T>>
Iterate over all rows in ValueGrid top to bottom.
Sourcepub fn iter_mut(&mut self) -> IterMut<'_, T>
pub fn iter_mut(&mut self) -> IterMut<'_, T>
Returns an iterator that allows modifying each value.
The iterator yields all cells from top left to bottom right.
Sourcepub fn get_ref_mut(&mut self, x: usize, y: usize) -> &mut T
pub fn get_ref_mut(&mut self, x: usize, y: usize) -> &mut T
Sourcepub fn get_ref_mut_optional(&mut self, x: usize, y: usize) -> Option<&mut T>
pub fn get_ref_mut_optional(&mut self, x: usize, y: usize) -> Option<&mut T>
Get a mutable reference to the current value at the specified position if position is in bounds.
§Arguments
xandy: position of the cell
returns: Reference to cell or None
Sourcepub fn map<TConverted, F>(&self, f: F) -> ValueGrid<TConverted>
pub fn map<TConverted, F>(&self, f: F) -> ValueGrid<TConverted>
Convert between ValueGrid types.
See also Iterator::map.
§Examples
Use logic written for u8s and then convert to Brightness values for sending in a Command.
let mut grid: ByteGrid = ByteGrid::new(TILE_WIDTH, TILE_HEIGHT);
foo(&mut grid);
let grid: BrightnessGrid = grid.map(Brightness::saturating_from);
let command = BrightnessGridCommand { origin: Origin::ZERO, grid };Sourcepub fn enumerate(&self) -> impl Iterator<Item = (usize, usize, T)> + use<'_, T>
pub fn enumerate(&self) -> impl Iterator<Item = (usize, usize, T)> + use<'_, T>
Enumerates all values in the grid.
Sourcepub fn window(
&self,
xs: impl RangeBounds<usize>,
ys: impl RangeBounds<usize>,
) -> Option<Window<'_, T, Self>>
pub fn window( &self, xs: impl RangeBounds<usize>, ys: impl RangeBounds<usize>, ) -> Option<Window<'_, T, Self>>
Creates a window into the grid.
Returns None in case the window does not fit.
Sourcepub fn window_mut(
&mut self,
xs: impl RangeBounds<usize>,
ys: impl RangeBounds<usize>,
) -> Option<WindowMut<'_, T, Self>>
pub fn window_mut( &mut self, xs: impl RangeBounds<usize>, ys: impl RangeBounds<usize>, ) -> Option<WindowMut<'_, T, Self>>
Creates a mutable window into the grid.
Returns None in case the window does not fit.
Trait Implementations§
Source§impl From<&ValueGrid<Brightness>> for ByteGrid
impl From<&ValueGrid<Brightness>> for ByteGrid
Source§fn from(value: &BrightnessGrid) -> Self
fn from(value: &BrightnessGrid) -> Self
Source§impl From<&ValueGrid<Brightness>> for Vec<u8>
impl From<&ValueGrid<Brightness>> for Vec<u8>
Source§fn from(value: &BrightnessGrid) -> Self
fn from(value: &BrightnessGrid) -> Self
Source§impl From<ValueGrid<Brightness>> for BrightnessGridCommand
impl From<ValueGrid<Brightness>> for BrightnessGridCommand
Source§fn from(grid: BrightnessGrid) -> Self
fn from(grid: BrightnessGrid) -> Self
Source§impl From<ValueGrid<Brightness>> for Vec<u8>
impl From<ValueGrid<Brightness>> for Vec<u8>
Source§fn from(value: BrightnessGrid) -> Self
fn from(value: BrightnessGrid) -> Self
Source§impl<T: Value> Grid<T> for ValueGrid<T>
impl<T: Value> Grid<T> for ValueGrid<T>
Source§fn get_optional(&self, x: usize, y: usize) -> Option<T>
fn get_optional(&self, x: usize, y: usize) -> Option<T>
Source§fn get(&self, x: usize, y: usize) -> T
fn get(&self, x: usize, y: usize) -> T
Source§fn is_in_bounds(&self, x: usize, y: usize) -> bool
fn is_in_bounds(&self, x: usize, y: usize) -> bool
Source§impl<T: Value> GridMut<T> for ValueGrid<T>
impl<T: Value> GridMut<T> for ValueGrid<T>
Source§fn set(&mut self, x: usize, y: usize, value: T)
fn set(&mut self, x: usize, y: usize, value: T)
Source§fn deref_assign<O: Grid<T>>(&mut self, other: &O)
fn deref_assign<O: Grid<T>>(&mut self, other: &O)
impl<T: Eq + Value> Eq for ValueGrid<T>
impl<T: Value> StructuralPartialEq for ValueGrid<T>
Auto Trait Implementations§
impl<T> Freeze for ValueGrid<T>
impl<T> RefUnwindSafe for ValueGrid<T>where
T: RefUnwindSafe,
impl<T> Send for ValueGrid<T>where
T: Send,
impl<T> Sync for ValueGrid<T>where
T: Sync,
impl<T> Unpin for ValueGrid<T>where
T: Unpin,
impl<T> UnwindSafe for ValueGrid<T>where
T: UnwindSafe,
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<G> CharGridExt for G
impl<G> CharGridExt for G
Source§impl<G> CharGridMutExt for G
impl<G> CharGridMutExt for G
Source§fn set_row_str(
&mut self,
y: usize,
value: &str,
) -> Result<(), SetValueSeriesError>
fn set_row_str( &mut self, y: usize, value: &str, ) -> Result<(), SetValueSeriesError>
Source§fn set_col_str(
&mut self,
x: usize,
value: &str,
) -> Result<(), SetValueSeriesError>
fn set_col_str( &mut self, x: usize, value: &str, ) -> Result<(), SetValueSeriesError>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.