[−][src]Struct ari::BitField
a bitfield.
this is c ffi compatible, which means for example a [u8; 4]
bitfield consumes 4 bytes of space. just like a
u32-based c-style bitfield.
examples.
let mut x: BitField<[u8; 4], u32> = BitField::new([0u8; 4]); assert_eq!(x.value(), &[0, 0, 0, 0]); x.set(0, true); x.set(4, true); x.set(8, true); x.set(16, true); x.set_value(20, 3, 7u64); assert_eq!(x.get(0), true); assert_eq!(x.get(4), true); assert_eq!(x.get(8), true); assert_eq!(x.get(16), true); assert_eq!(x.get_value(20, 3): u64, 7); assert_eq!(x.value(), &[17, 1, 113, 0]);
Methods
impl<TStorage, TAlignment> BitField<TStorage, TAlignment> where
TStorage: AsRef<[u8]> + AsMut<[u8]>,
[src]
TStorage: AsRef<[u8]> + AsMut<[u8]>,
pub fn new(storage: TStorage) -> Self
[src]
creates a new bitfield with the specified value.
examples.
let mut x: BitField<[u8; 4], u32> = BitField::new([0u8; 4]); assert_eq!(x.value(), &[0, 0, 0, 0]);
pub fn get(&self, index: usize) -> bool
[src]
retrieves the bit at index
.
examples.
let mut x: BitField<[u8; 4], u32> = BitField::new([0u8; 4]); assert_eq!(x.get(0), false);
pub fn set(&mut self, index: usize, value: bool)
[src]
places value
at the specified bit index
.
examples.
let mut x: BitField<[u8; 4], u32> = BitField::new([0u8; 4]); x.set(0, true); assert_eq!(x.get(0), true);
pub fn get_value<T>(&self, offset: usize, width: usize) -> T where
T: From<u64>,
[src]
T: From<u64>,
retrieves the value at the specified bit range [offset..offset + width]
.
examples.
let mut x: BitField<[u8; 4], u32> = BitField::new([0u8; 4]); x.set_value(0, 5, 0xfffffu64); assert_eq!(x.get_value::<u64>(0, 5), 31);
pub fn set_value<T>(&mut self, offset: usize, width: usize, value: T) where
T: Into<u64>,
[src]
T: Into<u64>,
places value
at the specified bit range [offset..offset + width]
.
value
is truncated if it exceeds the maximum representable value defined by (offset, width)
.
examples.
simple example.
let mut x: BitField<[u8; 4], u32> = BitField::new([0u8; 4]); x.set_value(0, 5, 0xfffffu64); assert_eq!(x.get_value(0, 5): u64, 31);
4 bit value truncated to 2 bits.
let mut x: BitField<[u8; 4], u32> = BitField::new([0u8; 4]); x.set_value(0, 2, 0b1111u64); assert_eq!(x.get_value(0, 4): u64, 0b11);
pub fn value(&self) -> &TStorage
[src]
returns the raw value of this bitfield.
examples.
let mut x: BitField<[u8; 4], u32> = BitField::new([0u8; 4]); x.set(0, true); x.set(4, true); x.set(8, true); x.set(16, true); x.set_value(20, 3, 9u64); assert_eq!(x.value(), &[17, 1, 17, 0]);
Trait Implementations
impl<TStorage: Clone, TAlignment: Clone> Clone for BitField<TStorage, TAlignment> where
TStorage: AsRef<[u8]> + AsMut<[u8]>,
[src]
TStorage: AsRef<[u8]> + AsMut<[u8]>,
fn clone(&self) -> BitField<TStorage, TAlignment>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<TStorage: Ord, TAlignment: Ord> Ord for BitField<TStorage, TAlignment> where
TStorage: AsRef<[u8]> + AsMut<[u8]>,
[src]
TStorage: AsRef<[u8]> + AsMut<[u8]>,
fn cmp(&self, other: &BitField<TStorage, TAlignment>) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
Compares and returns the minimum of two values. Read more
fn clamp(self, min: Self, max: Self) -> Self
[src]
clamp
)Restrict a value to a certain interval. Read more
impl<TStorage: Default, TAlignment: Default> Default for BitField<TStorage, TAlignment> where
TStorage: AsRef<[u8]> + AsMut<[u8]>,
[src]
TStorage: AsRef<[u8]> + AsMut<[u8]>,
impl<TStorage: PartialOrd, TAlignment: PartialOrd> PartialOrd<BitField<TStorage, TAlignment>> for BitField<TStorage, TAlignment> where
TStorage: AsRef<[u8]> + AsMut<[u8]>,
[src]
TStorage: AsRef<[u8]> + AsMut<[u8]>,
fn partial_cmp(
&self,
other: &BitField<TStorage, TAlignment>
) -> Option<Ordering>
[src]
&self,
other: &BitField<TStorage, TAlignment>
) -> Option<Ordering>
fn lt(&self, other: &BitField<TStorage, TAlignment>) -> bool
[src]
fn le(&self, other: &BitField<TStorage, TAlignment>) -> bool
[src]
fn gt(&self, other: &BitField<TStorage, TAlignment>) -> bool
[src]
fn ge(&self, other: &BitField<TStorage, TAlignment>) -> bool
[src]
impl<TStorage: PartialEq, TAlignment: PartialEq> PartialEq<BitField<TStorage, TAlignment>> for BitField<TStorage, TAlignment> where
TStorage: AsRef<[u8]> + AsMut<[u8]>,
[src]
TStorage: AsRef<[u8]> + AsMut<[u8]>,
fn eq(&self, other: &BitField<TStorage, TAlignment>) -> bool
[src]
fn ne(&self, other: &BitField<TStorage, TAlignment>) -> bool
[src]
impl<TStorage: Copy, TAlignment: Copy> Copy for BitField<TStorage, TAlignment> where
TStorage: AsRef<[u8]> + AsMut<[u8]>,
[src]
TStorage: AsRef<[u8]> + AsMut<[u8]>,
impl<TStorage: Eq, TAlignment: Eq> Eq for BitField<TStorage, TAlignment> where
TStorage: AsRef<[u8]> + AsMut<[u8]>,
[src]
TStorage: AsRef<[u8]> + AsMut<[u8]>,
impl<TStorage: Debug, TAlignment: Debug> Debug for BitField<TStorage, TAlignment> where
TStorage: AsRef<[u8]> + AsMut<[u8]>,
[src]
TStorage: AsRef<[u8]> + AsMut<[u8]>,
impl<TStorage: Hash, TAlignment: Hash> Hash for BitField<TStorage, TAlignment> where
TStorage: AsRef<[u8]> + AsMut<[u8]>,
[src]
TStorage: AsRef<[u8]> + AsMut<[u8]>,
Auto Trait Implementations
impl<TStorage, TAlignment> Sync for BitField<TStorage, TAlignment> where
TAlignment: Sync,
TStorage: Sync,
TAlignment: Sync,
TStorage: Sync,
impl<TStorage, TAlignment> Send for BitField<TStorage, TAlignment> where
TAlignment: Send,
TStorage: Send,
TAlignment: Send,
TStorage: Send,
impl<TStorage, TAlignment> Unpin for BitField<TStorage, TAlignment> where
TAlignment: Unpin,
TStorage: Unpin,
TAlignment: Unpin,
TStorage: Unpin,
impl<TStorage, TAlignment> RefUnwindSafe for BitField<TStorage, TAlignment> where
TAlignment: RefUnwindSafe,
TStorage: RefUnwindSafe,
TAlignment: RefUnwindSafe,
TStorage: RefUnwindSafe,
impl<TStorage, TAlignment> UnwindSafe for BitField<TStorage, TAlignment> where
TAlignment: UnwindSafe,
TStorage: UnwindSafe,
TAlignment: UnwindSafe,
TStorage: UnwindSafe,
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &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.
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>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,