Struct visioncortex::Field
source · pub struct Field<T> { /* private fields */ }
Expand description
Vec<T>
that represents a 2D field
Implementations§
source§impl<T> Field<T>
impl<T> Field<T>
The base implementation of Field
sourcepub fn with_vec(width: usize, height: usize, data: Vec<T>) -> Option<Self>
pub fn with_vec(width: usize, height: usize, data: Vec<T>) -> Option<Self>
Constructs a height
by width
field with data
.
Returns None
if the size of data
does not equal to height * width
.
sourcepub fn peek_mut(&mut self, index: usize) -> Option<&mut T>
pub fn peek_mut(&mut self, index: usize) -> Option<&mut T>
Returns a mutable reference to an element.
sourcepub fn replace(&mut self, index: usize, value: T) -> Option<T>
pub fn replace(&mut self, index: usize, value: T) -> Option<T>
Replaces an element with value
and returns the element.
sourcepub fn locate(&self, index: usize) -> (usize, usize)
pub fn locate(&self, index: usize) -> (usize, usize)
Returns the xy-coordinates representation of an index in the field.
sourcepub fn index_at(&self, x: usize, y: usize) -> usize
pub fn index_at(&self, x: usize, y: usize) -> usize
Returns the index of a xy-coordinates representation in the field.
pub fn iter(&self) -> impl Iterator + '_
pub fn iter_mut(&mut self) -> impl Iterator + '_
source§impl<T> Field<T>where
T: Default,
impl<T> Field<T>where
T: Default,
sourcepub fn with_default(width: usize, height: usize) -> Self
pub fn with_default(width: usize, height: usize) -> Self
Constructs a height
by width
field, with each slot filled with the default value of its element type.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Field<T>
impl<T> RefUnwindSafe for Field<T>where
T: RefUnwindSafe,
impl<T> Send for Field<T>where
T: Send,
impl<T> Sync for Field<T>where
T: Sync,
impl<T> Unpin for Field<T>where
T: Unpin,
impl<T> UnwindSafe for Field<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
Mutably borrows from an owned value. Read more