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>

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 copy 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>

§

type Item = T

The type of the elements being iterated over.
§

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> 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> ToOwned for T
where T: Clone,

§

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>,

§

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>,

§

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.