[][src]Struct accessor::single::Single

pub struct Single<T, M> where
    T: Copy,
    M: Mapper
{ /* fields omitted */ }

An accessor to read, modify, and write a single value of memory.

Examples

use accessor::mapper::Mapper;
use core::num::NonZeroUsize;

struct M;
impl Mapper for M {
    unsafe fn map(&mut self, phys_start: usize, bytes: usize) -> NonZeroUsize {
        unimplemented!()
    }

    fn unmap(&mut self, phys_start: usize, bytes: usize) {
        unimplemented!()
    }
}

let mapper = M;

// Create an accessor to the i32 value at the physical address 0x1000.
let mut a = unsafe { accessor::Single::<i32, M>::new(0x1000, mapper) };

// Read a value.
a.read();

// Write 42.
a.write(42);

// Update the value.
a.update(|v| {
    *v *= 2;
});

Implementations

impl<T, M> Single<T, M> where
    T: Copy,
    M: Mapper
[src]

pub unsafe fn new(phys_base: usize, mut mapper: M) -> Self[src]

Creates a new accessor to an element of type T at the physical address phys_base.

Safety

The caller must ensure the following conditions:

  • The value at the physical address phys_base is valid.
  • Any other accessors except the one returned by this method must not access the value while the returned one lives.

Panics

This method panics if phys_base is not aligned as the type T requires.

pub unsafe fn try_new(phys_base: usize, mapper: M) -> Result<Self, Error>[src]

Creates a new accessor to an element of type T at the physical address phys_base.

Safety

The caller must ensure the following conditions:

  • The value at the physical address phys_base is valid.
  • Any other accessors except the one returned by this method must not access the value while the returned one lives.

Errors

This method may return a Error::NotAligned error if phys_base is not aligned as the type T requires.

pub fn read(&self) -> T[src]

Reads a value from the address that the accessor points to.

pub fn write(&mut self, v: T)[src]

Writes a value to the address that the accessor points to.

pub fn update<U>(&mut self, f: U) where
    U: FnOnce(&mut T), 
[src]

Updates a value that the accessor points by reading it, modifying it, and writing it.

Note that some MMIO regions (e.g. the Command Ring Pointer field of the Command Ring Control Register of the xHCI) may return 0 regardless of the actual values of the fields. For these regions, this operation should be called only once.

Trait Implementations

impl<T, M> Debug for Single<T, M> where
    T: Copy + Debug,
    M: Mapper
[src]

impl<T, M> Drop for Single<T, M> where
    T: Copy,
    M: Mapper
[src]

impl<T, M> Eq for Single<T, M> where
    T: Copy + Eq,
    M: Mapper
[src]

impl<T, M> Hash for Single<T, M> where
    T: Copy + Hash,
    M: Mapper
[src]

impl<T, M> Ord for Single<T, M> where
    T: Copy + Ord,
    M: Mapper
[src]

impl<T, M> PartialEq<Single<T, M>> for Single<T, M> where
    T: Copy + PartialEq,
    M: Mapper
[src]

impl<T, M> PartialOrd<Single<T, M>> for Single<T, M> where
    T: Copy + PartialOrd,
    M: Mapper
[src]

Auto Trait Implementations

impl<T, M> Send for Single<T, M> where
    M: Send,
    T: Send
[src]

impl<T, M> Sync for Single<T, M> where
    M: Sync,
    T: Sync
[src]

impl<T, M> Unpin for Single<T, M> where
    M: Unpin,
    T: Unpin
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.