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

A read-only view for a subcell of a cell

Implementations§

source§

impl<'a, C: CellFamily> CellSlice<'a, C>

source

pub fn new(cell: &'a dyn Cell<C>) -> Self

Constructs a new cell slice from the specified cell.

source

pub const fn cell(&self) -> &'a dyn Cell<C>

Returns a reference to the underlying cell.

source

pub fn cell_type(&self) -> CellType

Computes cell type from descriptor bytes.

source

pub fn level(&self) -> u8

Computes the cell level from the level mask.

source

pub fn level_mask(&self) -> LevelMask

Computes the level mask from the descriptor bytes.

source

pub const fn is_data_empty(&self) -> bool

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());
source

pub const fn is_refs_empty(&self) -> bool

Returns whether there 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());
source

pub const fn remaining_refs(&self) -> u8

Returns the number of remaining references in the slice.

source

pub const fn remaining_bits(&self) -> u16

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

source

pub fn bits_offset(&self) -> u16

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);
source

pub const fn refs_offset(&self) -> u8

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);
source

pub const fn has_remaining(&self, bits: u16, refs: u8) -> bool

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
source

pub fn try_advance(&mut self, bits: u16, refs: u8) -> bool

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

source

pub fn get_prefix(&self, bits: u16, refs: u8) -> Self

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

source

pub fn strip_data_prefix( &self, prefix: &CellSlice<'a, C> ) -> Option<CellSlice<'a, C>>

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));
source

pub fn longest_common_data_prefix(&self, other: &Self) -> Self

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);
source

pub fn test_uniform(&self) -> Option<bool>

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_one();
    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);
source

pub fn get_bit(&self, offset: u16) -> Option<bool>

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

source

pub fn load_bit(&mut self) -> Option<bool>

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

source

pub fn get_u8(&self, offset: u16) -> Option<u8>

Reads u8 starting from the offset.

source

pub fn load_u8(&mut self) -> Option<u8>

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

source

pub fn get_u16(&self, offset: u16) -> Option<u16>

Reads u16 starting from the offset.

source

pub fn load_u16(&mut self) -> Option<u16>

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

source

pub fn get_u32(&self, offset: u16) -> Option<u32>

Reads u32 starting from the offset.

source

pub fn load_u32(&mut self) -> Option<u32>

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

source

pub fn get_u64(&self, offset: u16) -> Option<u64>

Reads u64 starting from the offset.

source

pub fn load_u64(&mut self) -> Option<u64>

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

source

pub fn get_u128(&self, offset: u16) -> Option<u128>

Reads u128 starting from the offset.

source

pub fn load_u128(&mut self) -> Option<u128>

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

source

pub fn get_u256(&self, offset: u16) -> Option<[u8; 32]>

Reads 32 bytes starting from the offset.

source

pub fn load_u256(&mut self) -> Option<[u8; 32]>

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

source

pub fn get_small_uint(&self, offset: u16, bits: u16) -> Option<u8>

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.

source

pub fn load_small_uint(&mut self, bits: u16) -> Option<u8>

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.

source

pub fn get_uint(&self, offset: u16, bits: u16) -> Option<u64>

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.

source

pub fn load_uint(&mut self, bits: u16) -> Option<u64>

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.

source

pub fn get_raw<'b>( &self, offset: u16, target: &'b mut [u8], bits: u16 ) -> Option<&'b mut [u8]>

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

source

pub fn load_raw<'b>( &mut self, target: &'b mut [u8], bits: u16 ) -> Option<&'b mut [u8]>

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

source

pub fn load_remaining(&mut self) -> CellSlice<'a, C>

Reads all remaining bits and refs into the new slice.

source

pub fn get_reference(&self, index: u8) -> Option<&'a dyn Cell<C>>

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

source

pub fn get_reference_cloned(&self, index: u8) -> Option<CellContainer<C>>

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

source

pub fn references(&self) -> RefsIter<'a, C>

Creates an iterator through child nodes.

source

pub fn into_references(self) -> RefsIter<'a, C>

Converts this slice into an iterator through child nodes.

source

pub fn without_references(self) -> Self

Returns this slice, but with references skipped.

source

pub fn load_reference(&mut self) -> Option<&'a dyn Cell<C>>

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

source

pub fn load_reference_cloned(&mut self) -> Option<CellContainer<C>>

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

Trait Implementations§

source§

impl<'a, C: CellFamily> Clone for CellSlice<'a, C>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a, C: CellFamily> Debug for CellSlice<'a, C>

source§

fn fmt(&self, __f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a, C: CellFamily> Load<'a, C> for CellSlice<'a, C>

source§

fn load_from(slice: &mut CellSlice<'a, C>) -> Option<Self>

Tries to load itself from a cell slice.
source§

impl<'a, C: CellFamily> Store<C> for CellSlice<'a, C>

source§

fn store_into( &self, builder: &mut CellBuilder<C>, _: &mut dyn Finalizer<C> ) -> bool

Tries to store itself into the cell builder.
source§

impl<'a, C: CellFamily> Copy for CellSlice<'a, C>

Auto Trait Implementations§

§

impl<'a, C> !RefUnwindSafe for CellSlice<'a, C>

§

impl<'a, C> !Send for CellSlice<'a, C>

§

impl<'a, C> !Sync for CellSlice<'a, C>

§

impl<'a, C> Unpin for CellSlice<'a, C>

§

impl<'a, C> !UnwindSafe for CellSlice<'a, C>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.