pub struct DmaMask(/* private fields */);
Expand description
A DMA mask that holds a bitmask with the lowest n
bits set.
Use DmaMask::new
or DmaMask::try_new
to construct a value. Values
are guaranteed to never exceed the bit width of u64
.
This is the Rust equivalent of the C macro DMA_BIT_MASK()
.
Implementations§
Source§impl DmaMask
impl DmaMask
Sourcepub const fn new<const N: u32>() -> Self
pub const fn new<const N: u32>() -> Self
Constructs a DmaMask
with the lowest n
bits set to 1
.
For n <= 64
, sets exactly the lowest n
bits.
For n > 64
, results in a build error.
§Examples
use kernel::dma::DmaMask;
let mask0 = DmaMask::new::<0>();
assert_eq!(mask0.value(), 0);
let mask1 = DmaMask::new::<1>();
assert_eq!(mask1.value(), 0b1);
let mask64 = DmaMask::new::<64>();
assert_eq!(mask64.value(), u64::MAX);
// Build failure.
// let mask_overflow = DmaMask::new::<100>();
Sourcepub const fn try_new(n: u32) -> Result<Self>
pub const fn try_new(n: u32) -> Result<Self>
Constructs a DmaMask
with the lowest n
bits set to 1
.
For n <= 64
, sets exactly the lowest n
bits.
For n > 64
, returns EINVAL
.
§Examples
use kernel::dma::DmaMask;
let mask0 = DmaMask::try_new(0)?;
assert_eq!(mask0.value(), 0);
let mask1 = DmaMask::try_new(1)?;
assert_eq!(mask1.value(), 0b1);
let mask64 = DmaMask::try_new(64)?;
assert_eq!(mask64.value(), u64::MAX);
let mask_overflow = DmaMask::try_new(100);
assert!(mask_overflow.is_err());
Trait Implementations§
impl Copy for DmaMask
impl Eq for DmaMask
impl StructuralPartialEq for DmaMask
Auto Trait Implementations§
impl Freeze for DmaMask
impl RefUnwindSafe for DmaMask
impl Send for DmaMask
impl Sync for DmaMask
impl Unpin for DmaMask
impl UnwindSafe for DmaMask
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> PinInit<T> for T
impl<T> PinInit<T> for T
Source§unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), Infallible>
unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), Infallible>
Initializes
slot
. Read more