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 theVolAddress
type returned when accessing the block in any way (indexing, iteration, etc).WIDTH
/HEIGHT
: the matrix width and height, the total element count isWIDTH * 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 theT
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>
impl<T, R, W, const WIDTH: usize, const HEIGHT: usize> VolGrid2d<T, R, W, WIDTH, HEIGHT>
sourcepub const unsafe fn new(address: usize) -> Self
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}>
.
sourcepub const fn from_block<const B: usize>(block: VolBlock<T, R, W, B>) -> Self
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.
sourcepub const fn into_block<const B: usize>(self) -> VolBlock<T, R, W, B>
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.
sourcepub const fn get(self, x: usize, y: usize) -> Option<VolAddress<T, R, W>>
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.
sourcepub const fn index(self, x: usize, y: usize) -> VolAddress<T, R, W>
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.
Trait Implementations§
source§impl<T, R, W, const WIDTH: usize, const HEIGHT: usize> Clone for VolGrid2d<T, R, W, WIDTH, HEIGHT>
impl<T, R, W, const WIDTH: usize, const HEIGHT: usize> Clone for VolGrid2d<T, R, W, WIDTH, HEIGHT>
source§impl<T: Hash, R: Hash, W: Hash, const WIDTH: usize, const HEIGHT: usize> Hash for VolGrid2d<T, R, W, WIDTH, HEIGHT>
impl<T: Hash, R: Hash, W: Hash, const WIDTH: usize, const HEIGHT: usize> Hash for VolGrid2d<T, R, W, WIDTH, HEIGHT>
source§impl<T: Ord, R: Ord, W: Ord, const WIDTH: usize, const HEIGHT: usize> Ord for VolGrid2d<T, R, W, WIDTH, HEIGHT>
impl<T: Ord, R: Ord, W: Ord, const WIDTH: usize, const HEIGHT: usize> Ord for VolGrid2d<T, R, W, WIDTH, HEIGHT>
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere Self: Sized,
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>
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§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>
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>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more