Struct everscale_types::cell::CellSlice
source · 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>
impl<'a, C: CellFamily> CellSlice<'a, C>
sourcepub fn level_mask(&self) -> LevelMask
pub fn level_mask(&self) -> LevelMask
Computes the level mask from the descriptor bytes.
sourcepub const fn is_data_empty(&self) -> bool
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());sourcepub const fn is_refs_empty(&self) -> bool
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());sourcepub const fn remaining_refs(&self) -> u8
pub const fn remaining_refs(&self) -> u8
Returns the number of remaining references in the slice.
sourcepub const fn remaining_bits(&self) -> u16
pub const fn remaining_bits(&self) -> u16
Returns the number of remaining bits of data in the slice.
sourcepub fn bits_offset(&self) -> u16
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);sourcepub const fn refs_offset(&self) -> u8
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);sourcepub const fn has_remaining(&self, bits: u16, refs: u8) -> bool
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 refssourcepub fn try_advance(&mut self, bits: u16, refs: u8) -> bool
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.
sourcepub fn get_prefix(&self, bits: u16, refs: u8) -> Self
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.
sourcepub fn strip_data_prefix(
&self,
prefix: &CellSlice<'a, C>
) -> Option<CellSlice<'a, C>>
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));sourcepub fn longest_common_data_prefix(&self, other: &Self) -> Self
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);sourcepub fn test_uniform(&self) -> Option<bool>
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);sourcepub fn get_bit(&self, offset: u16) -> Option<bool>
pub fn get_bit(&self, offset: u16) -> Option<bool>
Tries to read the bit at the specified offset (relative to the current bits window).
sourcepub fn load_bit(&mut self) -> Option<bool>
pub fn load_bit(&mut self) -> Option<bool>
Tries to read the next bit, incrementing the bits window start.
sourcepub fn load_u8(&mut self) -> Option<u8>
pub fn load_u8(&mut self) -> Option<u8>
Tries to read the next u8, incrementing the bits window start.
sourcepub fn load_u16(&mut self) -> Option<u16>
pub fn load_u16(&mut self) -> Option<u16>
Tries to read the next u16, incrementing the bits window start.
sourcepub fn load_u32(&mut self) -> Option<u32>
pub fn load_u32(&mut self) -> Option<u32>
Tries to read the next u32, incrementing the bits window start.
sourcepub fn load_u64(&mut self) -> Option<u64>
pub fn load_u64(&mut self) -> Option<u64>
Tries to read the next u64, incrementing the bits window start.
sourcepub fn load_u128(&mut self) -> Option<u128>
pub fn load_u128(&mut self) -> Option<u128>
Tries to read the next u128, incrementing the bits window start.
sourcepub fn get_u256(&self, offset: u16) -> Option<[u8; 32]>
pub fn get_u256(&self, offset: u16) -> Option<[u8; 32]>
Reads 32 bytes starting from the offset.
sourcepub fn load_u256(&mut self) -> Option<[u8; 32]>
pub fn load_u256(&mut self) -> Option<[u8; 32]>
Tries to read the next 32 bytes, incrementing the bits window start.
sourcepub fn get_small_uint(&self, offset: u16, bits: u16) -> Option<u8>
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.
sourcepub fn load_small_uint(&mut self, bits: u16) -> Option<u8>
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.
sourcepub fn get_uint(&self, offset: u16, bits: u16) -> Option<u64>
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.
sourcepub fn load_uint(&mut self, bits: u16) -> Option<u64>
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.
sourcepub fn get_raw<'b>(
&self,
offset: u16,
target: &'b mut [u8],
bits: u16
) -> Option<&'b mut [u8]>
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.
sourcepub fn load_raw<'b>(
&mut self,
target: &'b mut [u8],
bits: u16
) -> Option<&'b mut [u8]>
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.
sourcepub fn load_remaining(&mut self) -> CellSlice<'a, C>
pub fn load_remaining(&mut self) -> CellSlice<'a, C>
Reads all remaining bits and refs into the new slice.
sourcepub fn get_reference(&self, index: u8) -> Option<&'a dyn Cell<C>>
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).
sourcepub fn get_reference_cloned(&self, index: u8) -> Option<CellContainer<C>>
pub fn get_reference_cloned(&self, index: u8) -> Option<CellContainer<C>>
Returns the Nth child cell (relative to this slice’s refs window).
sourcepub fn get_reference_as_slice(
&self,
index: u8
) -> Result<CellSlice<'a, C>, Error>
pub fn get_reference_as_slice( &self, index: u8 ) -> Result<CellSlice<'a, C>, Error>
Tries to load the specified child cell as slice. Returns an error if the loaded cell is absent or is pruned.
sourcepub fn references(&self) -> RefsIter<'a, C> ⓘ
pub fn references(&self) -> RefsIter<'a, C> ⓘ
Creates an iterator through child nodes.
sourcepub fn into_references(self) -> RefsIter<'a, C> ⓘ
pub fn into_references(self) -> RefsIter<'a, C> ⓘ
Converts this slice into an iterator through child nodes.
sourcepub fn without_references(self) -> Self
pub fn without_references(self) -> Self
Returns this slice, but with references skipped.
sourcepub fn load_reference(&mut self) -> Option<&'a dyn Cell<C>>
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.
sourcepub fn load_reference_cloned(&mut self) -> Option<CellContainer<C>>
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.
sourcepub fn load_reference_as_slice(&mut self) -> Result<CellSlice<'a, C>, Error>
pub fn load_reference_as_slice(&mut self) -> Result<CellSlice<'a, C>, Error>
Tries to load the next child cell as slice. Returns an error if the loaded cell is absent or is pruned.
NOTE: In case of prunced cell access the current slice remains unchanged.