[−][src]Struct accessor::single::Single
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]
T: Copy,
M: Mapper,
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]
U: FnOnce(&mut T),
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]
T: Copy + Debug,
M: Mapper,
impl<T, M> Drop for Single<T, M> where
T: Copy,
M: Mapper,
[src]
T: Copy,
M: Mapper,
impl<T, M> Eq for Single<T, M> where
T: Copy + Eq,
M: Mapper,
[src]
T: Copy + Eq,
M: Mapper,
impl<T, M> Hash for Single<T, M> where
T: Copy + Hash,
M: Mapper,
[src]
T: Copy + Hash,
M: Mapper,
fn hash<H: Hasher>(&self, state: &mut H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<T, M> Ord for Single<T, M> where
T: Copy + Ord,
M: Mapper,
[src]
T: Copy + Ord,
M: Mapper,
fn cmp(&self, other: &Self) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl<T, M> PartialEq<Single<T, M>> for Single<T, M> where
T: Copy + PartialEq,
M: Mapper,
[src]
T: Copy + PartialEq,
M: Mapper,
impl<T, M> PartialOrd<Single<T, M>> for Single<T, M> where
T: Copy + PartialOrd,
M: Mapper,
[src]
T: Copy + PartialOrd,
M: Mapper,
Auto Trait Implementations
impl<T, M> Send for Single<T, M> where
M: Send,
T: Send,
[src]
M: Send,
T: Send,
impl<T, M> Sync for Single<T, M> where
M: Sync,
T: Sync,
[src]
M: Sync,
T: Sync,
impl<T, M> Unpin for Single<T, M> where
M: Unpin,
T: Unpin,
[src]
M: Unpin,
T: Unpin,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,