Allocator

Struct Allocator 

Source
pub struct Allocator {
    pub address: u32,
}
Expand description

Allocator for 28-bit memory

This can be used to allocate memory in 28-bit address space.

§Examples

The allocated 28-bit region is described by a fat Ptr28 pointer, which implements the From trait for common types such as Vec<u8> and String.

let mut bank = Allocator::new(0x40000);
let a = Vec::<u8>::from([7, 9, 13]);
let ptr = bank.write(a.as_slice()); // dma write
let b = Vec::<u8>::from(ptr); // dma read
assert_eq!(a, b);

Vec<Ptr28> can be traversed almost as if a vector of values:

let cnt = Vec::from([bank.push(b"first"), bank.push(b"second")])
     .iter()
     .copied()
     .map(String::from) // dma write
     .filter(|s| s.starts_with('s'))
     .count();
assert_eq!(cnt, 1);

Fields§

§address: u32

Current 28-bit address

Implementations§

Source§

impl Allocator

Source

pub const fn new(address: u32) -> Self

New allocator starting at address

Source

pub fn write(&mut self, bytes: &[u8]) -> Ptr28

DMA copy bytes to next free 28-bit memory location.

Every call to write advances the address by bytes.len().

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
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, 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.