pub struct Sp<T, D = InMemoryDB>{
pub child_repr: ArenaKey<<D as DB>::Hasher>,
pub arena: Arena<D>,
pub root: ArenaHash<<D as DB>::Hasher>,
/* private fields */
}Expand description
A typed pointer to a value stored in the Arena.
An Sp<T> can be lazily initialized, in which case its internal T value
won’t be loaded until access is attempted.
Fields§
§child_repr: ArenaKey<<D as DB>::Hasher>This Sp represented as a child node (for easy access)
arena: Arena<D>The arena this Sp points into
root: ArenaHash<<D as DB>::Hasher>The persistent hash of data.
Implementations§
Source§impl<T, D> Sp<T, D>
Constructors for Sp that take care of Arena ref counting.
impl<T, D> Sp<T, D>
Constructors for Sp that take care of Arena ref counting.
Sourcepub fn into_tracked(&self) -> Sp<T, D>
pub fn into_tracked(&self) -> Sp<T, D>
Converts this Sp into one that is tracked directly, making it possible to lookup by its hash.
This forces the Sp to be considered a reference when used as a child of other Sps, and places it into internal caches, and eventually the database if persisted or a parent is persisted.
Source§impl<D> Sp<dyn Any + Send + Sync, D>where
D: DB,
impl<D> Sp<dyn Any + Send + Sync, D>where
D: DB,
Sourcepub fn downcast<T>(&self) -> Option<Sp<T, D>>
pub fn downcast<T>(&self) -> Option<Sp<T, D>>
Downcasts this dynamically typed pointer to a concrete type, if possible.
Sourcepub fn force_downcast<T>(&self) -> Sp<T, D>
pub fn force_downcast<T>(&self) -> Sp<T, D>
Downcasts this dynamically typed pointer to a concrete type, but pushes through the cast regardless of the underlying type.
This will effectively unload the Sp, and construct a new lazy Sp with the same backing data. There is no way of knowing if this will succeed, as the lazy loading will defer failure to a context where a failure panics.
Source§impl<T, D> Sp<T, D>
impl<T, D> Sp<T, D>
Sourcepub fn is_lazy(&self) -> bool
pub fn is_lazy(&self) -> bool
Return true iff this Sp is lazy/unforced, i.e. its data has not yet
been loaded.
If the Sp is lazy, it can be forced by dereferencing it.
Sourcepub fn hash(&self) -> ArenaHash<<D as DB>::Hasher>
pub fn hash(&self) -> ArenaHash<<D as DB>::Hasher>
Return hash of self and all children, cached from <T as Storable>::hash().
This is the root key of self, as a content-addressed Merkle node.
Sourcepub fn as_typed_key(&self) -> TypedArenaKey<T, <D as DB>::Hasher>
pub fn as_typed_key(&self) -> TypedArenaKey<T, <D as DB>::Hasher>
Returns the TypedArenaKey representation of this Sp, useful as a
reference to persist.
Source§impl<T, D> Sp<T, D>
impl<T, D> Sp<T, D>
Sourcepub fn persist(&mut self)
pub fn persist(&mut self)
Notify the storage back-end to increment the persist count on this object.
See [StorageBackend::persist].
Note: Due to a technicality in past behaviour, this converts the Sp into a Ref
internally. In particular, this means that Sp::as_typed_key will provide different
results before and after persisting. A change to this would be a major breaking
change, and is therefore deferred.
Sourcepub fn unpersist(&self)
pub fn unpersist(&self)
Notify the storage back-end to decrement the persist count on this object.
See [StorageBackend::unpersist].
Sourcepub fn into_inner(this: Sp<T, D>) -> Option<T>
pub fn into_inner(this: Sp<T, D>) -> Option<T>
Returns the content of this Sp, if this Sp is initialized, and is
the only reference to its data. When the Sp is initialized, this
behaves like Arc::into_inner.
Source§impl<T, D> Sp<T, D>
impl<T, D> Sp<T, D>
Sourcepub fn unload(&mut self)
pub fn unload(&mut self)
Replace the self.data with an uninitialized lazy value.
Note: if there are multiple outstanding refs to the data in this Sp,
e.g. because a clone of this Sp is owned by some larger data
structure, then the underlying data won’t actually be dropped until all
such Sps go out of scope or have unload called on them.
Warning: If this is the last reference to the Sp, and the Sp is not persisted, dereferencing it after unload may fail, because nothing is keeping the data alive.
Source§impl<T, D> Sp<T, D>
impl<T, D> Sp<T, D>
Sourcepub fn serialize_to_node_list(&self) -> TopoSortedNodes
pub fn serialize_to_node_list(&self) -> TopoSortedNodes
Topologically sort a sub-graph of storage into a sequence of nodes.
This will force and load all nodes in this sub-graph.
Sourcepub fn serialize_to_node_list_bounded(
&self,
raw_size_limit: u64,
) -> Option<TopoSortedNodes>
pub fn serialize_to_node_list_bounded( &self, raw_size_limit: u64, ) -> Option<TopoSortedNodes>
Topologically sort a sub-graph of storage into a sequence of nodes.
This will force and load all nodes in this sub-graph.
The size limit stops serialization if a specified serialized size limit is overstepped.
Only returns None if a size limit is provided and overstepped
Trait Implementations§
Source§impl<T, D> Deserializable for Sp<T, D>
impl<T, D> Deserializable for Sp<T, D>
Source§impl<'a, T, D> Deserialize<'a> for Sp<T, D>
impl<'a, T, D> Deserialize<'a> for Sp<T, D>
Source§fn deserialize<D2>(
deserializer: D2,
) -> Result<Sp<T, D>, <D2 as Deserializer<'a>>::Error>where
D2: Deserializer<'a>,
fn deserialize<D2>(
deserializer: D2,
) -> Result<Sp<T, D>, <D2 as Deserializer<'a>>::Error>where
D2: Deserializer<'a>,
Source§impl<T, D> Ord for Sp<T, D>
See warning on Sp::eq above.
impl<T, D> Ord for Sp<T, D>
See warning on Sp::eq above.
Source§impl<T, D> PartialEq for Sp<T, D>where
D: DB,
impl<T, D> PartialEq for Sp<T, D>where
D: DB,
Source§fn eq(&self, other: &Sp<T, D>) -> bool
fn eq(&self, other: &Sp<T, D>) -> bool
An O(1) implementation of equality for Sp<T>.
§Warning
It’s possible this implementation is inconsistent with the
implementation for the underlying type T, if any, because:
-
our equality is reflexive, but equality on
Tmay not be, i.e.Tmight not implementEq. -
our equality is maximally fine grained, but equality on the underlying type
Tcould equate two values with different hashes.
Source§impl<T, D> PartialOrd for Sp<T, D>
See warning on Sp::eq above.
impl<T, D> PartialOrd for Sp<T, D>
See warning on Sp::eq above.
Source§impl<T, D> Serializable for Sp<T, D>
impl<T, D> Serializable for Sp<T, D>
Source§impl<T, D> Serialize for Sp<T, D>
impl<T, D> Serialize for Sp<T, D>
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Source§impl<D, T> Storable<D> for Sp<T, D>
impl<D, T> Storable<D> for Sp<T, D>
Source§fn children(&self) -> Vec<ArenaKey<<D as DB>::Hasher>>
fn children(&self) -> Vec<ArenaKey<<D as DB>::Hasher>>
Sps, if any. These hashes
will be passed back into from_binary_repr when deserializing.Source§fn from_binary_repr<R>(
reader: &mut R,
child_hashes: &mut impl Iterator<Item = ArenaKey<<D as DB>::Hasher>>,
loader: &impl Loader<D>,
) -> Result<Sp<T, D>, Error>where
R: Read,
fn from_binary_repr<R>(
reader: &mut R,
child_hashes: &mut impl Iterator<Item = ArenaKey<<D as DB>::Hasher>>,
loader: &impl Loader<D>,
) -> Result<Sp<T, D>, Error>where
R: Read,
Source§fn to_binary_repr<W>(&self, writer: &mut W) -> Result<(), Error>where
W: Write,
fn to_binary_repr<W>(&self, writer: &mut W) -> Result<(), Error>where
W: Write,
Source§impl<D> Storable<D> for Sp<dyn Any + Send + Sync, D>where
D: DB,
impl<D> Storable<D> for Sp<dyn Any + Send + Sync, D>where
D: DB,
Source§fn children(&self) -> Vec<ArenaKey<<D as DB>::Hasher>>
fn children(&self) -> Vec<ArenaKey<<D as DB>::Hasher>>
Sps, if any. These hashes
will be passed back into from_binary_repr when deserializing.Source§fn from_binary_repr<R>(
reader: &mut R,
child_nodes: &mut impl Iterator<Item = ArenaKey<<D as DB>::Hasher>>,
loader: &impl Loader<D>,
) -> Result<Sp<dyn Any + Send + Sync, D>, Error>
fn from_binary_repr<R>( reader: &mut R, child_nodes: &mut impl Iterator<Item = ArenaKey<<D as DB>::Hasher>>, loader: &impl Loader<D>, ) -> Result<Sp<dyn Any + Send + Sync, D>, Error>
Source§fn to_binary_repr<W>(&self, writer: &mut W) -> Result<(), Error>
fn to_binary_repr<W>(&self, writer: &mut W) -> Result<(), Error>
Source§impl<T, D> Tagged for Sp<T, D>
impl<T, D> Tagged for Sp<T, D>
Source§fn tag() -> Cow<'static, str>
fn tag() -> Cow<'static, str>
Self. Returns a [Cow] as type arguments require allocation, but no
allocation is preferred.Source§fn tag_unique_factor() -> String
fn tag_unique_factor() -> String
(a,b)), and sum types (via [a,b]). Read moreimpl<T, D> Eq for Sp<T, D>where
D: DB,
See warning on Sp::eq above.
Auto Trait Implementations§
impl<T, D = InMemoryDB> !Freeze for Sp<T, D>
impl<T, D = InMemoryDB> !RefUnwindSafe for Sp<T, D>
impl<T, D> Send for Sp<T, D>
impl<T, D> Sync for Sp<T, D>
impl<T, D> Unpin for Sp<T, D>where
<<<D as DB>::Hasher as OutputSizeUser>::OutputSize as ArrayLength<u8>>::ArrayType: Unpin,
T: ?Sized,
impl<T, D> UnsafeUnpin for Sp<T, D>where
<<<D as DB>::Hasher as OutputSizeUser>::OutputSize as ArrayLength<u8>>::ArrayType: UnsafeUnpin,
T: ?Sized,
impl<T, D = InMemoryDB> !UnwindSafe for Sp<T, D>
Blanket Implementations§
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,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.