Struct quartet::NibSlice [−][src]
pub struct NibSlice<'a> { /* fields omitted */ }
Expand description
A const slice (&[u4]
) over nibbles (4-bit values)
Internally, it operates on an array of bytes, and interprets them as pairs of nibbles. This is
intended to allow use of a NibSlice
to examine binary structures that are composed of
nibbles.
For each byte, the nibble composed of the lower bits (mask = 0x0f
) is considered to come
before the nibble composed of the higher bits (mask = 0xf0
).
Implementations
Create a NibSlice
from a slice of bytes and whether to exclude either end of the slice
Create a NibSlice
from a slice of bytes, excluding the last nibble in the slice
Index, using various ranges, a NibSlice
into NibSlice
s that are sub-slices
Examples
use quartet::{NibSlice, Exclude}; let ns = NibSlice::from_bytes_exclude(&[0x12, 0x34, 0x56], Exclude::Both); let n = ns.index(2..4); assert_eq!(n, NibSlice::from_bytes(&[0x45]));
Get the NibSlice
refered to by the indexing value, or return None
if index is out of
range
If the slice refers to a single nibble, return that nibble as a byte. Panic if slice does not have exactly one nibble
Examples
use quartet::{NibSlice, Exclude}; let orig_s = NibSlice::from_bytes_exclude(&[0x02, 0x34], Exclude::First); let nib_s = orig_s.index(..1); assert_eq!(nib_s.len(), 1); let nib = nib_s.nibble(); assert_eq!(nib, 0x2);
If the slice refers to a single nibble, return that nibble as a byte. Return None if the slice does not have exactly one nibble
Examples
use quartet::{NibSlice, Exclude}; let orig_s = NibSlice::from_bytes_exclude(&[0x02, 0x34], Exclude::First); let nib_s = orig_s.index(..1); let nib = nib_s.try_nibble(); assert_eq!(nib, Some(0x2)); // more than 1 nibble assert_eq!(orig_s.index(1..3).try_nibble(), None);
Create an iterator over the NibSlice
, where each item is a nibble
Trait Implementations
Auto Trait Implementations
impl<'a> RefUnwindSafe for NibSlice<'a>
impl<'a> UnwindSafe for NibSlice<'a>
Blanket Implementations
Mutably borrows from an owned value. Read more