Canvas

Struct Canvas 

Source
pub struct Canvas<T> {
    pub data: Vec<T>,
    pub width: usize,
    pub height: usize,
}
Expand description

A struct containing a single vector abstracted to a 2 dimensional array.

§Arguments

data The actual data, stored as a Vec<T> width The width of the canvas height The height of the canvas

§Note

The canvas is repesented by a single vector of type <T>. The canvas can be interpreted in any direction, but it was intended to start at the top left corner, and goes from left to right, up to down.

The functions provided allow access to each elemeny by row and column, as well as access to iterators over the whole canvas. If you prefer the raw data, then you can access the data field directly.

Fields§

§data: Vec<T>§width: usize§height: usize

Implementations§

Source§

impl<T: Clone> Canvas<T>

Source

pub fn new(width: usize, height: usize, background_data: T) -> Canvas<T>

Creates a new canvas of the specified size. The background data is the default data that will fill the canvas at initialization.

Background data type must implement the Clone trait.

Source

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

Return the pixel value at the specified row and column.

Source

pub fn get_mut(&mut self, row: usize, col: usize) -> Option<&mut T>

Return a mutable reference to the pixel at the specified row and column.

Source

pub fn iter(&self) -> Iter<'_, T>

Returns an iterator over all the pixels in the canvas, starting from top left, scanning left to right, top to bottom.

Source

pub fn iter_mut(&mut self) -> IterMut<'_, T>

Returns a mutable iterator over all the pixels in the canvas, starting from top left, scanning left ot right, top to bottom.

Trait Implementations§

Source§

impl<T: Clone> Clone for Canvas<T>

Source§

fn clone(&self) -> Canvas<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

Auto Trait Implementations§

§

impl<T> Freeze for Canvas<T>

§

impl<T> RefUnwindSafe for Canvas<T>
where T: RefUnwindSafe,

§

impl<T> Send for Canvas<T>
where T: Send,

§

impl<T> Sync for Canvas<T>
where T: Sync,

§

impl<T> Unpin for Canvas<T>
where T: Unpin,

§

impl<T> UnwindSafe for Canvas<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> 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.