Skip to main content

BufferMapping

Struct BufferMapping 

Source
pub struct BufferMapping {
    ptr: NonNull<u8>,
    len: u64,
    mode: MapMode,
    _guard: RwLockReadGuard<'static, BufferMapState>,
    _lock: Arc<RwLock<BufferMapState>>,
}
Expand description

Represents a mapped range in the buffer.

While returned BufferMapping is alive, Buffer::destroy and Buffer::unmap calls will block until BufferMapping is dropped.

Fields§

§ptr: NonNull<u8>§len: u64§mode: MapMode§_guard: RwLockReadGuard<'static, BufferMapState>§_lock: Arc<RwLock<BufferMapState>>

Implementations§

Source§

impl BufferMapping

Source

fn new( ptr: NonNull<u8>, len: u64, mode: MapMode, lock: Arc<RwLock<BufferMapState>>, ) -> Self

Source

pub fn ptr(&self) -> NonNull<u8>

§How to safely use the pointer
  • Pointer is only accessed for the length returned by BufferMapping::len.
  • Pointer is only accessed while BufferMapping is alive.
  • Reading is allowed if BufferMapping::mode is [MapMode::Read] (buffer has [wgt::BufferUsages::MAP_READ] set).
  • Writing is allowed if BufferMapping::mode is [MapMode::Write] (buffer has [wgt::BufferUsages::MAP_WRITE] set).
  • Atomics must not be used through the pointer since read-modify-write operations may not function on write-combining memory. This also means that it’s not safe to create rust references from this pointer since rust’s memory model requires atomic operations to work.
Source

pub fn mode(&self) -> MapMode

Source

pub fn len(&self) -> u64

Source

pub fn read_into_vec(&self, offset: usize) -> Vec<u8> ⓘ

Read the contents of the mapped buffer from offset into a Vec<u8>. BufferMapping::mode must be [MapMode::Read] (buffer has [wgt::BufferUsages::MAP_READ] set) otherwise it will panic.

Source

pub fn read(&self, dst: &mut [u8], offset: usize)

Read the contents of the mapped buffer into dst starting from offset. BufferMapping::mode must be [MapMode::Read] (buffer has [wgt::BufferUsages::MAP_READ] set) otherwise it will panic.

Source

pub fn write_slice(&self) -> WriteOnly<'_, [u8]>

Returns a write-only slice to the mapped buffer. BufferMapping::mode must be [MapMode::Write] (buffer has [wgt::BufferUsages::MAP_WRITE] set) otherwise it will panic.

Trait Implementations§

Source§

impl Debug for BufferMapping

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. 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.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,