pub struct Field<T> { /* private fields */ }
Expand description
Vec<T>
that represents a 2D field
Implementations§
Source§impl<T> Field<T>
The base implementation of Field
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§
Source§impl<T> IntoIterator for Field<T>
impl<T> IntoIterator for Field<T>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more