Struct voladdress::VolGrid2d

source ·
#[repr(transparent)]
pub struct VolGrid2d<T, R, W, const WIDTH: usize, const HEIGHT: usize> { /* private fields */ }
Expand description

A 2D version of VolBlock, with a const generic WIDTH and HEIGHT.

This is intended for “video-like” memory that is better to logically access with an x and y position rather than a single i index. It’s just an alternative way to manage a VolBlock.

Generic Parameters

  • T / R / W: These parameters are applied to the VolAddress type returned when accessing the block in any way (indexing, iteration, etc).
  • WIDTH / HEIGHT: the matrix width and height, the total element count is WIDTH * HEIGHT.

Safety

  • This type stores a base VolAddress internally, and so you must follow all of those safety rules. Notably, the base address must never be zero.
  • The address space must legally contain WIDTH * HEIGHT contiguous values of the T type, starting from the base address.
  • The memory block must not wrap around past the end of the address space.

Implementations§

source§

impl<T, R, W, const WIDTH: usize, const HEIGHT: usize> VolGrid2d<T, R, W, WIDTH, HEIGHT>

source

pub const unsafe fn new(address: usize) -> Self

Converts the address into a VolGrid2d

Safety

The given address must be a valid VolAddress at each position in the grid, as if you were making a VolBlock<T,R,W,{WIDTH * HEIGHT}>.

source

pub const fn from_block<const B: usize>(block: VolBlock<T, R, W, B>) -> Self

Creates a VolGrid2d from an appropriately sized VolBlock.

Panics

When B != WIDTH * HEIGHT. Note that such a panic should happen at compile time.

source

pub const fn into_block<const B: usize>(self) -> VolBlock<T, R, W, B>

Turn a VolGrid2d into its VolBlock equivalent.

Panics

When B != WIDTH * HEIGHT. Note that such a panic should happen at compile time.

source

pub const fn get(self, x: usize, y: usize) -> Option<VolAddress<T, R, W>>

Gets the address of the (x,y) given.

Returns None if either coordinate it out of bounds.

source

pub const fn index(self, x: usize, y: usize) -> VolAddress<T, R, W>

Indexes the address of the (x,y) given.

Panics
  • If either coordinate it out of bounds this will panic.
source

pub const fn get_row(self, y: usize) -> Option<VolBlock<T, R, W, WIDTH>>

Get a single row of the grid as a VolBlock.

source

pub const fn as_usize(self) -> usize

Converts the VolGrid2d the usize for the start of the grid.

Trait Implementations§

source§

impl<T, R, W, const WIDTH: usize, const HEIGHT: usize> Clone for VolGrid2d<T, R, W, WIDTH, HEIGHT>

source§

fn clone(&self) -> Self

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: Hash, R: Hash, W: Hash, const WIDTH: usize, const HEIGHT: usize> Hash for VolGrid2d<T, R, W, WIDTH, HEIGHT>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<T: Ord, R: Ord, W: Ord, const WIDTH: usize, const HEIGHT: usize> Ord for VolGrid2d<T, R, W, WIDTH, HEIGHT>

source§

fn cmp(&self, other: &VolGrid2d<T, R, W, WIDTH, HEIGHT>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl<T: PartialEq, R: PartialEq, W: PartialEq, const WIDTH: usize, const HEIGHT: usize> PartialEq<VolGrid2d<T, R, W, WIDTH, HEIGHT>> for VolGrid2d<T, R, W, WIDTH, HEIGHT>

source§

fn eq(&self, other: &VolGrid2d<T, R, W, WIDTH, HEIGHT>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: PartialOrd, R: PartialOrd, W: PartialOrd, const WIDTH: usize, const HEIGHT: usize> PartialOrd<VolGrid2d<T, R, W, WIDTH, HEIGHT>> for VolGrid2d<T, R, W, WIDTH, HEIGHT>

source§

fn partial_cmp( &self, other: &VolGrid2d<T, R, W, WIDTH, HEIGHT> ) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<T, R, W, const WIDTH: usize, const HEIGHT: usize> Copy for VolGrid2d<T, R, W, WIDTH, HEIGHT>

source§

impl<T: Eq, R: Eq, W: Eq, const WIDTH: usize, const HEIGHT: usize> Eq for VolGrid2d<T, R, W, WIDTH, HEIGHT>

source§

impl<T, R, W, const WIDTH: usize, const HEIGHT: usize> StructuralEq for VolGrid2d<T, R, W, WIDTH, HEIGHT>

source§

impl<T, R, W, const WIDTH: usize, const HEIGHT: usize> StructuralPartialEq for VolGrid2d<T, R, W, WIDTH, HEIGHT>

Auto Trait Implementations§

§

impl<T, R, W, const WIDTH: usize, const HEIGHT: usize> RefUnwindSafe for VolGrid2d<T, R, W, WIDTH, HEIGHT>where R: RefUnwindSafe, T: RefUnwindSafe, W: RefUnwindSafe,

§

impl<T, R, W, const WIDTH: usize, const HEIGHT: usize> Send for VolGrid2d<T, R, W, WIDTH, HEIGHT>where R: Send, T: Send, W: Send,

§

impl<T, R, W, const WIDTH: usize, const HEIGHT: usize> Sync for VolGrid2d<T, R, W, WIDTH, HEIGHT>where R: Sync, T: Sync, W: Sync,

§

impl<T, R, W, const WIDTH: usize, const HEIGHT: usize> Unpin for VolGrid2d<T, R, W, WIDTH, HEIGHT>where R: Unpin, T: Unpin, W: Unpin,

§

impl<T, R, W, const WIDTH: usize, const HEIGHT: usize> UnwindSafe for VolGrid2d<T, R, W, WIDTH, HEIGHT>where R: UnwindSafe, T: UnwindSafe, W: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.