pub enum NodeRef {
Node(Arc<Node>, OnceLock<NodeHash>),
Hash(NodeHash),
}Expand description
A reference to a node.
Explicit rkyv bounds are needed because this is a recursive type, whose bounds can’t be automatically resolved.
Variants§
Node(Arc<Node>, OnceLock<NodeHash>)
The node is embedded within the reference.
Hash(NodeHash)
The node is in the database, referenced by its hash.
Implementations§
Source§impl NodeRef
impl NodeRef
Sourcepub fn get_node(
&self,
db: &dyn TrieDB,
path: Nibbles,
) -> Result<Option<Arc<Node>>, TrieError>
pub fn get_node( &self, db: &dyn TrieDB, path: Nibbles, ) -> Result<Option<Arc<Node>>, TrieError>
Gets a shared reference to the inner node. Requires that the trie is in a consistent state, ie that all leaves being pointed are in the database. Outside of snapsync this should always be the case.
Sourcepub fn get_node_checked(
&self,
db: &dyn TrieDB,
path: Nibbles,
) -> Result<Option<Arc<Node>>, TrieError>
pub fn get_node_checked( &self, db: &dyn TrieDB, path: Nibbles, ) -> Result<Option<Arc<Node>>, TrieError>
Gets a shared reference to the inner node, checking its hash.
Returns Ok(None) if the hash is invalid.
Uses NativeCrypto directly because this function is only reachable from
native storage/sync paths (get_root_node, get_proof, validate,
verify_range, trie iterator) — never from the guest program path, which
traverses via Node::get().
pub fn is_valid(&self) -> bool
pub fn commit( &mut self, path: Nibbles, acc: &mut Vec<(Nibbles, Vec<u8>)>, crypto: &dyn Crypto, ) -> NodeHash
pub fn compute_hash(&self, crypto: &dyn Crypto) -> NodeHash
pub fn compute_hash_ref(&self, crypto: &dyn Crypto) -> &NodeHash
pub fn compute_hash_no_alloc( &self, buf: &mut Vec<u8>, crypto: &dyn Crypto, ) -> &NodeHash
pub fn memoize_hashes(&self, buf: &mut Vec<u8>, crypto: &dyn Crypto)
Sourcepub fn clear_hash(&mut self)
pub fn clear_hash(&mut self)
Resets the memoized hash of this Node
This is used when mutating a node in place, in which case the memoized hash is not valid anymore.
Trait Implementations§
Source§impl Archive for NodeRef
impl Archive for NodeRef
Source§type Archived = ArchivedNodeRef
type Archived = ArchivedNodeRef
Source§type Resolver = NodeRefResolver
type Resolver = NodeRefResolver
Source§fn resolve(
&self,
resolver: <Self as Archive>::Resolver,
out: Place<<Self as Archive>::Archived>,
)
fn resolve( &self, resolver: <Self as Archive>::Resolver, out: Place<<Self as Archive>::Archived>, )
Source§const COPY_OPTIMIZATION: CopyOptimization<Self> = _
const COPY_OPTIMIZATION: CopyOptimization<Self> = _
serialize. Read moreSource§impl<'de> Deserialize<'de> for NodeRef
impl<'de> Deserialize<'de> for NodeRef
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl !Freeze for NodeRef
impl RefUnwindSafe for NodeRef
impl Send for NodeRef
impl Sync for NodeRef
impl Unpin for NodeRef
impl UnsafeUnpin for NodeRef
impl UnwindSafe for NodeRef
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> ArchiveUnsized for Twhere
T: Archive,
impl<T> ArchiveUnsized for Twhere
T: Archive,
Source§type Archived = <T as Archive>::Archived
type Archived = <T as Archive>::Archived
Archive, it may be
unsized. Read moreSource§fn archived_metadata(
&self,
) -> <<T as ArchiveUnsized>::Archived as ArchivePointee>::ArchivedMetadata
fn archived_metadata( &self, ) -> <<T as ArchiveUnsized>::Archived as ArchivePointee>::ArchivedMetadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.