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
impl BufferMapping
fn new( ptr: NonNull<u8>, len: u64, mode: MapMode, lock: Arc<RwLock<BufferMapState>>, ) -> Self
Sourcepub fn ptr(&self) -> NonNull<u8>
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
BufferMappingis alive. - Reading is allowed if
BufferMapping::modeis [MapMode::Read] (buffer has [wgt::BufferUsages::MAP_READ] set). - Writing is allowed if
BufferMapping::modeis [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.
pub fn mode(&self) -> MapMode
pub fn len(&self) -> u64
Sourcepub fn read_into_vec(&self, offset: usize) -> Vec<u8> ⓘ
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.
Sourcepub fn read(&self, dst: &mut [u8], offset: usize)
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.
Sourcepub fn write_slice(&self) -> WriteOnly<'_, [u8]>
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§
Auto Trait Implementations§
impl Freeze for BufferMapping
impl !RefUnwindSafe for BufferMapping
impl !Send for BufferMapping
impl !Sync for BufferMapping
impl Unpin for BufferMapping
impl UnsafeUnpin for BufferMapping
impl !UnwindSafe for BufferMapping
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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