#[repr(transparent)]
pub struct ByteAddressableBuffer<'a> { pub data: &'a mut [u32], }
Expand description

ByteAddressableBuffer is an untyped blob of data, allowing loads and stores of arbitrary basic data types at arbitrary indicies. However, all data must be aligned to size 4, each element within the data (e.g. struct fields) must have a size and alignment of a multiple of 4, and the byte_index passed to load and store must be a multiple of 4 (byte_index will be rounded down to the nearest multiple of 4). So, it’s not technically a byte addressable buffer, but rather a word buffer, but this naming and behavior was inhereted from HLSL (where it’s UB to pass in an index not a multiple of 4).

Fields§

§data: &'a mut [u32]

The underlying array of bytes, able to be directly accessed.

Implementations§

source§

impl<'a> ByteAddressableBuffer<'a>

source

pub fn new(data: &'a mut [u32]) -> Self

Creates a ByteAddressableBuffer from the untyped blob of data.

source

pub unsafe fn load<T>(&self, byte_index: u32) -> T

Loads an arbitrary type from the buffer. byte_index must be a multiple of 4, otherwise, it will get silently rounded down to the nearest multiple of 4.

Safety

This function allows writing a type to an untyped buffer, then reading a different type from the same buffer, allowing all sorts of safety guarantees to be bypassed (effectively a transmute)

source

pub unsafe fn load_unchecked<T>(&self, byte_index: u32) -> T

Loads an arbitrary type from the buffer. byte_index must be a multiple of 4, otherwise, it will get silently rounded down to the nearest multiple of 4. Bounds checking is not performed.

Safety

This function allows writing a type to an untyped buffer, then reading a different type from the same buffer, allowing all sorts of safety guarantees to be bypassed (effectively a transmute). Additionally, bounds checking is not performed.

source

pub unsafe fn store<T>(&mut self, byte_index: u32, value: T)

Stores an arbitrary type int the buffer. byte_index must be a multiple of 4, otherwise, it will get silently rounded down to the nearest multiple of 4.

Safety

This function allows writing a type to an untyped buffer, then reading a different type from the same buffer, allowing all sorts of safety guarantees to be bypassed (effectively a transmute)

source

pub unsafe fn store_unchecked<T>(&mut self, byte_index: u32, value: T)

Stores an arbitrary type int the buffer. byte_index must be a multiple of 4, otherwise, it will get silently rounded down to the nearest multiple of 4. Bounds checking is not performed.

Safety

This function allows writing a type to an untyped buffer, then reading a different type from the same buffer, allowing all sorts of safety guarantees to be bypassed (effectively a transmute). Additionally, bounds checking is not performed.

Auto Trait Implementations§

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,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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, U> TryFrom<U> for Twhere 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 Twhere 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.