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

Create a NibSlice from a slice of bytes, including all nibbles in the given bytes

The resulting NibSlice will have .len() equal to 2 * inner.len().

The number of nibbles in the NibSlice

Split the NibSlice into 2 NibSlices at the nibble offset given

The nibble at offset is included in the second slice returned

Index, using various ranges, a NibSlice into NibSlices 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

Decompose the NibSlice into byte-oriented parts

The first and last members of the tuple are the non-byte aligned nibbles optionally at the start and end of the NibSlice. The middle member is the byte-aligned nibbles organized into bytes

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.