Skip to main content

SliceMut

Trait SliceMut 

Source
pub trait SliceMut: MemoryDescriptor + 'static {
    // Required method
    unsafe fn as_slice_mut(&mut self) -> Result<&mut [u8], StorageError>;

    // Provided methods
    fn slice_mut(
        &mut self,
        offset: usize,
        len: usize,
    ) -> Result<&mut [u8], StorageError> { ... }
    fn as_slice_typed_mut<T: Sized>(&mut self) -> Result<&mut [T], StorageError> { ... }
    fn slice_typed_mut<T: Sized>(
        &mut self,
        offset: usize,
        len: usize,
    ) -> Result<&mut [T], StorageError> { ... }
}
Expand description

Extension trait for storage types that support mutable slicing operations.

Required Methods§

Source

unsafe fn as_slice_mut(&mut self) -> Result<&mut [u8], StorageError>

Returns a mutable byte slice view of the entire storage region

§Safety

This is an unsafe method. The caller must ensure:

  • The memory region remains valid for the lifetime of the returned slice
  • The memory region is valid and accessible
  • No other references (mutable or immutable) exist to this memory region
  • The memory backing this storage remains valid (implementors with owned memory satisfy this, but care must be taken with unowned memory regions)

Provided Methods§

Source

fn slice_mut( &mut self, offset: usize, len: usize, ) -> Result<&mut [u8], StorageError>

Returns a mutable byte slice view of a subregion

§Arguments
  • offset - Offset in bytes from the start of the storage
  • len - Number of bytes to slice
§Safety

The caller must ensure:

  • offset + len <= self.size()
  • The memory region is valid
  • No other references (mutable or immutable) exist to this memory region
Source

fn as_slice_typed_mut<T: Sized>(&mut self) -> Result<&mut [T], StorageError>

Returns a typed mutable slice view of the entire storage region

§Safety

The caller must ensure:

  • The memory region is valid
  • The memory is properly aligned for type T
  • The size is a multiple of size_of::<T>()
  • No other references (mutable or immutable) exist to this memory region
Source

fn slice_typed_mut<T: Sized>( &mut self, offset: usize, len: usize, ) -> Result<&mut [T], StorageError>

Returns a typed mutable slice view of a subregion

§Arguments
  • offset - Offset in bytes from the start of the storage
  • len - Number of elements of type T to slice
§Safety

The caller must ensure:

  • offset + (len * size_of::()) <= self.size()
  • offset is properly aligned for type T
  • The memory region is valid
  • No other references (mutable or immutable) exist to this memory region

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§