Struct Lazy

Source
pub struct Lazy<T, const EXOTIC: bool = false> { /* private fields */ }
Expand description

Lazy-loaded model.

Implementations§

Source§

impl<T, const EXOTIC: bool> Lazy<T, EXOTIC>

Source

pub fn from_raw(cell: Cell) -> Result<Self, Error>

Wraps the cell in a typed wrapper.

Source

pub unsafe fn from_raw_unchecked(cell: Cell) -> Self

Wraps the cell in a typed wrapper.

§Safety

The cell is_exotic flag must be in sync with EXOTIC type param.

Source

pub fn into_inner(self) -> Cell

Converts into the underlying cell.

Source

pub fn inner(&self) -> &Cell

Returns the underlying cell.

Source

pub fn cast_into<Q>(self) -> Lazy<Q, EXOTIC>
where Q: EquivalentRepr<T>,

Converts into a lazy loader for an equivalent type.

Source

pub fn cast_ref<Q>(&self) -> &Lazy<Q, EXOTIC>
where Q: EquivalentRepr<T>,

Casts itself into a lazy loaded for an equivalent type.

Source

pub fn serialize_repr_hash<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serializes only the root hash of the cell.

Source§

impl<T: Store, const EXOTIC: bool> Lazy<T, EXOTIC>

Source

pub fn new(data: &T) -> Result<Self, Error>

Serializes the provided data and returns the typed wrapper around it.

Source

pub fn set(&mut self, data: &T) -> Result<(), Error>

Updates the content with the provided data.

Source§

impl<'a, T: Load<'a> + 'a> Lazy<T, false>

Source

pub fn load(&'a self) -> Result<T, Error>

Loads inner data from cell expecting an ordinary cell.

Source§

impl<'a, T: LoadCell<'a> + 'a> Lazy<T, true>

Source

pub fn load(&'a self) -> Result<T, Error>

Loads inner data from cell expecting an exotic cell.

Methods from Deref<Target = DynCell>§

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 fn reference_count(&self) -> u8

Computes the number of child cells from descriptor bytes.

Source

pub fn get_reference_as_slice(&self, index: u8) -> Result<CellSlice<'_>, Error>

Tries to load the specified child cell as slice. Returns an error if the loaded cell is absent or is pruned.

Source

pub fn is_exotic(&self) -> bool

Returns whether the cell is not Ordinary.

Source

pub fn repr_hash(&self) -> &HashBytes

Returns a representation hash of the cell.

Source

pub fn repr_depth(&self) -> u16

Returns a representation depth of the cell.

Source

pub fn has_max_depth(&self) -> bool

Returns true if any of cell levels has the maximum depth.

Source

pub fn is_empty(&self) -> bool

Returns true if the cell is empty (no bits, no refs).

Source

pub fn references(&self) -> RefsIter<'_>

Creates an iterator through child nodes.

Source

pub fn as_slice(&self) -> Result<CellSlice<'_>, Error>

Returns this cell as a cell slice. Returns an error if the cell is not ordinary.

Source

pub fn as_slice_allow_exotic(&self) -> CellSlice<'_>

Returns this cell as a cell slice.

Loads cell as is.

Source

pub fn compute_unique_stats(&self, limit: usize) -> Option<CellTreeStats>

Recursively computes the count of distinct cells returning the total storage used by this dag taking into account the identification of equal cells.

Source

pub fn touch_recursive(&self)

Recursively traverses the cells tree without tracking a uniqueness of cells. Usefull for adding small subtrees to merkle proofs.

Source

pub fn debug_root(&self) -> DebugCell<'_>

Returns an object that implements Debug for printing only the root cell of the cell tree.

Source

pub fn display_root(&self) -> DisplayCellRoot<'_>

Returns an object that implements Display for printing only the root cell of the cell tree.

Source

pub fn display_tree(&self) -> DisplayCellTree<'_>

Returns an object that implements Display for printing all cells in the cell tree.

Source

pub fn display_data(&self) -> impl Display + Binary + '_

Returns an object which will display cell data as a bitstring with a termination bit.

Source

pub fn parse<'a, T: Load<'a>>(&'a self) -> Result<T, Error>

Converts this cell into a slice and tries to load the specified type from it. Fails if the cell is not ordinary.

NOTE: parsing Cell will load the first reference!

Source

pub fn parse_exotic<'a, T: LoadCell<'a>>(&'a self) -> Result<T, Error>

Loads an exotic cell.

Trait Implementations§

Source§

impl<T, const EXOTIC: bool> AsRef<dyn CellImpl + Sync + Send> for Lazy<T, EXOTIC>

Source§

fn as_ref(&self) -> &DynCell

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T, const EXOTIC: bool> Clone for Lazy<T, EXOTIC>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for Lazy<T, false>

Source§

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

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

impl<T> Debug for Lazy<T, true>

Source§

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

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

impl<T, const EXOTIC: bool> Deref for Lazy<T, EXOTIC>

Source§

type Target = Cell

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<'de, T, const EXOTIC: bool> Deserialize<'de> for Lazy<T, EXOTIC>
where T: Deserialize<'de> + Store,

Source§

fn deserialize<D>(deserializer: D) -> Result<Lazy<T, EXOTIC>, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T, const EXOTIC: bool> ExactSize for Lazy<T, EXOTIC>

Source§

fn exact_size(&self) -> Size

Exact size of the value when it is stored in a slice.
Source§

impl<'a, T, const EXOTIC: bool> Load<'a> for Lazy<T, EXOTIC>

Source§

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

Tries to load itself from a cell slice.
Source§

impl<T, const EXOTIC: bool> PartialEq<&Cell> for Lazy<T, EXOTIC>

Source§

fn eq(&self, other: &&Cell) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

const fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T, const EXOTIC: bool> PartialEq<&Lazy<T, EXOTIC>> for Cell

Source§

fn eq(&self, other: &&Lazy<T, EXOTIC>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

const fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T, const EXOTIC: bool> PartialEq<Cell> for Lazy<T, EXOTIC>

Source§

fn eq(&self, other: &Cell) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

const fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T, const EXOTIC: bool> PartialEq<Lazy<T, EXOTIC>> for Cell

Source§

fn eq(&self, other: &Lazy<T, EXOTIC>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

const fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T, const EXOTIC: bool> PartialEq for Lazy<T, EXOTIC>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

const fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> Serialize for Lazy<T, false>
where for<'a> T: Serialize + Load<'a>,

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T> Serialize for Lazy<T, true>
where for<'a> T: Serialize + LoadCell<'a>,

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T, const EXOTIC: bool> Store for Lazy<T, EXOTIC>

Source§

fn store_into( &self, builder: &mut CellBuilder, _: &dyn CellContext, ) -> Result<(), Error>

Tries to store itself into the cell builder.
Source§

impl<T: WithAbiType> WithAbiType for Lazy<T>

Source§

fn abi_type() -> AbiType

Returns a corresponding ABI type.
Source§

impl<T, const EXOTIC: bool> Eq for Lazy<T, EXOTIC>

Auto Trait Implementations§

§

impl<T, const EXOTIC: bool> Freeze for Lazy<T, EXOTIC>

§

impl<T, const EXOTIC: bool = false> !RefUnwindSafe for Lazy<T, EXOTIC>

§

impl<T, const EXOTIC: bool> Send for Lazy<T, EXOTIC>
where T: Send,

§

impl<T, const EXOTIC: bool> Sync for Lazy<T, EXOTIC>
where T: Sync,

§

impl<T, const EXOTIC: bool> Unpin for Lazy<T, EXOTIC>
where T: Unpin,

§

impl<T, const EXOTIC: bool = false> !UnwindSafe for Lazy<T, EXOTIC>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compares self to key and returns true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> EquivalentRepr<T> for T