MemoryMapper

Trait MemoryMapper 

Source
pub trait MemoryMapper {
    // Required methods
    fn create(address: usize, size: usize) -> Result<Self, &'static str>
       where Self: Sized;
    fn len(&self) -> usize;
    fn as_ptr<T>(&self) -> *const T;
    fn as_mut_ptr<T>(&mut self) -> *mut T;

    // Provided methods
    fn is_empty(&self) -> bool { ... }
    fn as_range(&self, range: impl RangeBounds<usize>) -> &[u8]  { ... }
    fn as_mut_range(&mut self, range: impl RangeBounds<usize>) -> &mut [u8]  { ... }
}
Expand description

Maps a memory region to a pointer.

Required Methods§

Source

fn create(address: usize, size: usize) -> Result<Self, &'static str>
where Self: Sized,

Create a Mapper that maps the given physical address and size.

Source

fn len(&self) -> usize

Returns the maximum length that can be addressed. The end of this memory mapped range is address + len().

Source

fn as_ptr<T>(&self) -> *const T

Returns a pointer to the mapped memory region.

Source

fn as_mut_ptr<T>(&mut self) -> *mut T

Returns a mutable pointer to the mapped memory region.

Provided Methods§

Source

fn is_empty(&self) -> bool

Returns true if the mapping is empty.

Source

fn as_range(&self, range: impl RangeBounds<usize>) -> &[u8]

Creates an inner range of bytes. The offsets are relative to the base of the mapped memory, e.g. as_range(0..4) will return the first 4 bytes of the mapped memory (a memory mapping to address 0x12340000 will map 0x12340000..0x12340004).

Source

fn as_mut_range(&mut self, range: impl RangeBounds<usize>) -> &mut [u8]

Creates an inner mutable range of bytes.

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§