pub struct CellSlice<'a, C: CellFamily> { /* private fields */ }
Expand description

A read-only view for a subcell of a cell

Implementations§

Constructs a new cell slice from the specified cell.

Returns a reference to the underlying cell.

Computes cell type from descriptor bytes.

Computes the cell level from the level mask.

Computes the level mask from the descriptor bytes.

Returns whether there are no bits of data left.

Examples
// Cell with empty data
let empty_cell = RcCellFamily::empty_cell();
assert!(empty_cell.as_slice().is_data_empty());

// Cell with some bits in data
let not_empty_cell = {
    let mut builder = RcCellBuilder::new();
    builder.store_bit_zero();
    builder.build().unwrap()
};
assert!(!not_empty_cell.as_slice().is_data_empty());

Returns whether threre are no references left.

Examples
// Cell without references
let empty_cell = RcCellFamily::empty_cell();
assert!(empty_cell.as_slice().is_refs_empty());

// Cell with some references
let not_empty_cell = {
    let mut builder = RcCellBuilder::new();
    builder.store_reference(empty_cell);
    builder.build().unwrap()
};
assert!(!not_empty_cell.as_slice().is_refs_empty());

Returns the number of remaining references in the slice.

Returns the number of remaining bits of data in the slice.

Returns the start of the data window.

Examples
let cell = {
    let mut builder = RcCellBuilder::new();
    builder.store_zeros(100);
    builder.build().unwrap()
};
let mut slice = cell.as_slice();

_ = slice.load_u8();
assert_eq!(slice.bits_offset(), 8);

Returns the start of the references window.

Examples
let cell = {
    let mut builder = RcCellBuilder::new();
    builder.store_reference(RcCellFamily::empty_cell());
    builder.build().unwrap()
};
let mut slice = cell.as_slice();

_ = slice.load_reference();
assert_eq!(slice.refs_offset(), 1);

Returns true if the slice contains at least bits and refs.

Examples
let cell = {
    let mut builder = RcCellBuilder::new();
    builder.store_zeros(100);
    builder.store_reference(RcCellFamily::empty_cell());
    builder.store_reference(RcCellFamily::empty_cell());
    builder.build().unwrap()
};
let mut slice = cell.as_slice();

assert!(slice.has_remaining(10, 2));
assert!(!slice.has_remaining(500, 2)); // too many bits
assert!(!slice.has_remaining(0, 4)); // too many refs

Tries to advance the start of data and refs windows, returns false if bits or refs are greater than the remainder.

Returns a slice starting at the same bits and refs offsets, and containing no more than bits of data and refs of children.

Returns a subslice with the data prefix removed.

If the slice starts with prefix, returns the subslice after the prefix, wrapped in Some. If prefix is empty, simply returns the original slice.

If the slice does not start with prefix, returns None.

Examples
let cell = {
    let mut builder = RcCellBuilder::new();
    builder.store_u32(0xdeadbeaf);
    builder.build().unwrap()
};
let slice = cell.as_slice();

let prefix = {
    let mut builder = RcCellBuilder::new();
    builder.store_u16(0xdead);
    builder.build().unwrap()
};

let without_prefix = slice.strip_data_prefix(&prefix.as_slice()).unwrap();
assert_eq!(without_prefix.get_u16(0), Some(0xbeaf));

Returns the longest common data prefix.

NOTE: The returned subslice will be a subslice of the current slice.

Examples
let cell = {
    let mut builder = RcCellBuilder::new();
    builder.store_u32(0xdeadbeaf);
    builder.build().unwrap()
};
let slice = cell.as_slice();

let prefix = {
    let mut builder = RcCellBuilder::new();
    builder.store_u16(0xdead);
    builder.build().unwrap()
};

let lcp = slice.longest_common_data_prefix(&prefix.as_slice());
assert_eq!(lcp.get_u16(0), Some(0xdead));
assert_eq!(lcp.remaining_bits(), 16);

Checks whether the current slice consists of the same bits, returns None if there are 0s and 1s, returns Some(bit) otherwise.

Examples
// Uniform cell consisting of only 0s
let uniform_cell = {
    let mut builder = RcCellBuilder::new();
    builder.store_zeros(10);
    builder.build().unwrap()
};
assert_eq!(uniform_cell.as_slice().test_uniform(), Some(false));

// Non-uniform cell consisting of 0s and 1s
let non_uniform_cell = {
    let mut builder = RcCellBuilder::new();
    builder.store_zeros(9);
    builder.store_bit_true();
    builder.build().unwrap()
};
assert_eq!(non_uniform_cell.as_slice().test_uniform(), None);

// Empty cell is non-uniform
let non_uniform_cell = RcCellFamily::empty_cell();
assert_eq!(non_uniform_cell.as_slice().test_uniform(), None);

Tries to read the bit at the specified offset (relative to the current bits window).

Tries to read the next bit, incrementing the bits window start.

Reads u8 starting from the offset.

Tries to read the next u8, incrementing the bits window start.

Reads u16 starting from the offset.

Tries to read the next u16, incrementing the bits window start.

Reads u32 starting from the offset.

Tries to read the next u32, incrementing the bits window start.

Reads u64 starting from the offset.

Tries to read the next u64, incrementing the bits window start.

Reads u128 starting from the offset.

Tries to read the next u128, incrementing the bits window start.

Reads 32 bytes starting from the offset.

Tries to read the next 32 bytes, incrementing the bits window start.

Returns a small subset of bits (0..=8) starting from the offset.

NOTE: Reading zero bits always succeeds, and reading more than 8 bits always fails.

Tries to read the next small subset of bits (0..=8), incrementing the bits window start.

NOTE: Reading zero bits always succeeds, and reading more than 8 bits always fails.

Reads u64 from the cell (but only the specified number of bits) starting from the offset.

NOTE: Reading zero bits always succeeds, and reading more than 64 bits always fails.

Tries to read the next u64 (but only the specified number of bits), incrementing the bits window start.

NOTE: Reading zero bits always succeeds, and reading more than 64 bits always fails.

Reads the specified number of bits to the taret starting from the offset.

Tries to read the specified number of bits, incrementing the bits window start. Returns the minimum subslice containing all bits.

Returns a reference to the Nth child cell (relative to this slice’s refs window).

Returns the Nth child cell (relative to this slice’s refs window).

Creates an iterator through child nodes.

Converts this slice into an iterator through child nodes.

Returins this slice, but with references skipped.

Returns a reference to the next child cell (relative to this slice’s refs window), incrementing the refs window start.

Returns the next child cell (relative to this slice’s refs window), incrementing the refs window start.

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

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

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. 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.