Struct Field

Source
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

Source

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.

Source

pub fn width(&self) -> usize

Returns the width of the field.

Source

pub fn height(&self) -> usize

Returns the height of the field.

Source

pub fn peek(&self, index: usize) -> Option<&T>

Returns a reference to an element.

Source

pub fn peek_mut(&mut self, index: usize) -> Option<&mut T>

Returns a mutable reference to an element.

Source

pub fn replace(&mut self, index: usize, value: T) -> Option<T>

Replaces an element with value and returns the element.

Source

pub fn locate(&self, index: usize) -> (usize, usize)

Returns the xy-coordinates representation of an index in the field.

Source

pub fn index_at(&self, x: usize, y: usize) -> usize

Returns the index of a xy-coordinates representation in the field.

Source

pub fn iter(&self) -> impl Iterator + '_

Source

pub fn iter_mut(&mut self) -> impl Iterator + '_

Source§

impl<T> Field<T>
where T: Default,

Source

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.

Source§

impl<T> Field<T>
where T: Clone,

Source

pub fn with_initial(width: usize, height: usize, value: T) -> Self

Constructs a height by width field, with each slot filled with value.

Source

pub fn get(&self, index: usize) -> Option<T>

Returns a copy of an element.

Source

pub fn set(&mut self, index: usize, value: &T)

Assigns a copy of a value to a slot.

Trait Implementations§

Source§

impl<T: Clone> Clone for Field<T>

Source§

fn clone(&self) -> Field<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Default> Default for Field<T>

Source§

fn default() -> Field<T>

Returns the “default value” for a type. Read more
Source§

impl<T> IntoIterator for Field<T>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<<Field<T> as IntoIterator>::Item>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.