pub struct HistoricallyHashableView<C, W> { /* private fields */ }Expand description
Wrapper to compute the hash of the view based on its history of modifications.
Implementations§
Source§impl<W: View> HistoricallyHashableView<W::Context, W>
impl<W: View> HistoricallyHashableView<W::Context, W>
Sourcepub async fn historical_hash(&mut self) -> Result<HasherOutput, ViewError>
pub async fn historical_hash(&mut self) -> Result<HasherOutput, ViewError>
Obtains a hash of the history of the changes in the view.
Sourcepub async fn dump_content(
&mut self,
) -> Result<(Vec<u8>, HasherOutput), ViewError>
pub async fn dump_content( &mut self, ) -> Result<(Vec<u8>, HasherOutput), ViewError>
Returns the canonical byte representation of the inner view’s persisted content and arranges for the next save to record the hash of those bytes as the new stored hash. Subsequent updates extend the history from that hash normally.
The bytes are the BCS encoding of Vec<(Vec<u8>, Vec<u8>)> — every entry stored
under the inner view’s prefix, in sorted lexicographic key order. Two views with
identical persisted content produce identical bytes by construction; the hash is
therefore reproducible by any party holding the bytes.
Errors with ViewError::HasPendingChanges if the inner view has unflushed
changes — the dump reads from the underlying KV store and would silently miss
in-memory modifications.
Sourcepub async fn restore_from_content(
&mut self,
bytes: &[u8],
) -> Result<HasherOutput, ViewError>
pub async fn restore_from_content( &mut self, bytes: &[u8], ) -> Result<HasherOutput, ViewError>
Replaces the inner view’s persisted content with bytes (a prior dump_content
output) and atomically records the hash of those bytes as the new stored hash.
Returns the recorded hash, so the caller can compare against an expected value.
The replacement is save-atomic: this method writes a single batch containing the
inner-prefix wipe, the decoded (key, value) puts, and the wrapper’s hash key.
The wrapper’s normal pre_save lifecycle is bypassed.
The inner view’s in-memory state is undefined after this returns. Callers should drop the view and reload before using it further.
Trait Implementations§
Source§impl<C, W: Allocative> Allocative for HistoricallyHashableView<C, W>
impl<C, W: Allocative> Allocative for HistoricallyHashableView<C, W>
Source§impl<W> ClonableView for HistoricallyHashableView<W::Context, W>where
W: ClonableView,
impl<W> ClonableView for HistoricallyHashableView<W::Context, W>where
W: ClonableView,
Source§fn clone_unchecked(&mut self) -> Result<Self, ViewError>
fn clone_unchecked(&mut self) -> Result<Self, ViewError>
Source§impl<C, W> Deref for HistoricallyHashableView<C, W>
impl<C, W> Deref for HistoricallyHashableView<C, W>
Source§impl<C, W> DerefMut for HistoricallyHashableView<C, W>
impl<C, W> DerefMut for HistoricallyHashableView<C, W>
Source§impl<C, W> OutputType for HistoricallyHashableView<C, W>
impl<C, W> OutputType for HistoricallyHashableView<C, W>
Source§fn qualified_type_name() -> String
fn qualified_type_name() -> String
Source§fn create_type_info(registry: &mut Registry) -> String
fn create_type_info(registry: &mut Registry) -> String
Source§async fn resolve(
&self,
ctx: &ContextSelectionSet<'_>,
field: &Positioned<Field>,
) -> ServerResult<Value>
async fn resolve( &self, ctx: &ContextSelectionSet<'_>, field: &Positioned<Field>, ) -> ServerResult<Value>
async_graphql::Value.Source§impl<C, W, C2> ReplaceContext<C2> for HistoricallyHashableView<C, W>
impl<C, W, C2> ReplaceContext<C2> for HistoricallyHashableView<C, W>
Source§type Target = HistoricallyHashableView<C2, <W as ReplaceContext<C2>>::Target>
type Target = HistoricallyHashableView<C2, <W as ReplaceContext<C2>>::Target>
Source§impl<W> View for HistoricallyHashableView<W::Context, W>where
W: View,
impl<W> View for HistoricallyHashableView<W::Context, W>where
W: View,
Source§const NUM_INIT_KEYS: usize
const NUM_INIT_KEYS: usize
Source§fn pre_load(context: &Self::Context) -> Result<Vec<Vec<u8>>, ViewError>
fn pre_load(context: &Self::Context) -> Result<Vec<Vec<u8>>, ViewError>
Source§fn post_load(
context: Self::Context,
values: &[Option<Vec<u8>>],
) -> Result<Self, ViewError>
fn post_load( context: Self::Context, values: &[Option<Vec<u8>>], ) -> Result<Self, ViewError>
Source§fn rollback(&mut self)
fn rollback(&mut self)
flush should have no effect to storage.Source§async fn has_pending_changes(&self) -> bool
async fn has_pending_changes(&self) -> bool
true if flushing this view would result in changes to the persistent storage.Source§fn pre_save(&self, batch: &mut Batch) -> Result<bool, ViewError>
fn pre_save(&self, batch: &mut Batch) -> Result<bool, ViewError>
batch variable.
The returned boolean indicates whether the operation removes the view or not.Source§fn post_save(&mut self)
fn post_save(&mut self)
pre_save and after the batch has been successfully written to storage.
This leaves the view in a clean state with no pending changes. Read moreAuto Trait Implementations§
impl<C, W> !Freeze for HistoricallyHashableView<C, W>
impl<C, W> RefUnwindSafe for HistoricallyHashableView<C, W>where
W: RefUnwindSafe,
C: RefUnwindSafe,
impl<C, W> Send for HistoricallyHashableView<C, W>
impl<C, W> Sync for HistoricallyHashableView<C, W>
impl<C, W> Unpin for HistoricallyHashableView<C, W>
impl<C, W> UnsafeUnpin for HistoricallyHashableView<C, W>where
W: UnsafeUnpin,
impl<C, W> UnwindSafe for HistoricallyHashableView<C, W>where
W: UnwindSafe,
C: UnwindSafe,
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<P> AsEngineRef for P
impl<P> AsEngineRef for P
Source§fn as_engine_ref(&self) -> EngineRef<'_>
fn as_engine_ref(&self) -> EngineRef<'_>
EngineRef pointing to the underlying context.Source§impl<P> AsStoreMut for P
impl<P> AsStoreMut for P
Source§fn as_store_mut(&mut self) -> StoreMut<'_>
fn as_store_mut(&mut self) -> StoreMut<'_>
StoreMut pointing to the underlying context.Source§fn objects_mut(&mut self) -> &mut StoreObjects
fn objects_mut(&mut self) -> &mut StoreObjects
Source§impl<P> AsStoreRef for P
impl<P> AsStoreRef for P
Source§fn as_store_ref(&self) -> StoreRef<'_>
fn as_store_ref(&self) -> StoreRef<'_>
StoreRef pointing to the underlying context.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<Choices> CoproductSubsetter<CNil, HNil> for Choices
impl<Choices> CoproductSubsetter<CNil, HNil> for Choices
Source§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
Source§impl<T, A> DynAccess<T> for A
impl<T, A> DynAccess<T> for A
Source§fn load(&self) -> DynGuard<T>
fn load(&self) -> DynGuard<T>
Access::load.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> 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> MockResults for T
impl<T> MockResults for T
Source§type Results = T
type Results = T
MockInstance.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R> Rng for R
impl<R> Rng for R
Source§fn random<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
fn random<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
StandardUniform distribution. Read moreSource§fn random_iter<T>(self) -> Iter<StandardUniform, Self, T>
fn random_iter<T>(self) -> Iter<StandardUniform, Self, T>
Source§fn random_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
fn random_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
Source§fn random_bool(&mut self, p: f64) -> bool
fn random_bool(&mut self, p: f64) -> bool
p of being true. Read moreSource§fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
numerator/denominator of being
true. Read moreSource§fn sample<T, D>(&mut self, distr: D) -> Twhere
D: Distribution<T>,
fn sample<T, D>(&mut self, distr: D) -> Twhere
D: Distribution<T>,
Source§fn sample_iter<T, D>(self, distr: D) -> Iter<D, Self, T>where
D: Distribution<T>,
Self: Sized,
fn sample_iter<T, D>(self, distr: D) -> Iter<D, Self, T>where
D: Distribution<T>,
Self: Sized,
Source§fn gen<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
fn gen<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
random to avoid conflict with the new gen keyword in Rust 2024.Rng::random.Source§fn gen_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
fn gen_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
random_rangeRng::random_range.Source§impl<M, I> RuntimeMemory<&mut I> for Mwhere
M: RuntimeMemory<I>,
impl<M, I> RuntimeMemory<&mut I> for Mwhere
M: RuntimeMemory<I>,
Source§fn read<'instance>(
&self,
instance: &'instance &mut I,
location: GuestPointer,
length: u32,
) -> Result<Cow<'instance, [u8]>, RuntimeError>
fn read<'instance>( &self, instance: &'instance &mut I, location: GuestPointer, length: u32, ) -> Result<Cow<'instance, [u8]>, RuntimeError>
Reads length bytes from memory from the provided location.
Source§fn write(
&mut self,
instance: &mut &mut I,
location: GuestPointer,
bytes: &[u8],
) -> Result<(), RuntimeError>
fn write( &mut self, instance: &mut &mut I, location: GuestPointer, bytes: &[u8], ) -> Result<(), RuntimeError>
Writes the bytes to memory at the provided location.
Source§impl<R> TryRngCore for R
impl<R> TryRngCore for R
Source§type Error = Infallible
type Error = Infallible
Source§fn try_next_u32(&mut self) -> Result<u32, <R as TryRngCore>::Error>
fn try_next_u32(&mut self) -> Result<u32, <R as TryRngCore>::Error>
u32.Source§fn try_next_u64(&mut self) -> Result<u64, <R as TryRngCore>::Error>
fn try_next_u64(&mut self) -> Result<u64, <R as TryRngCore>::Error>
u64.Source§fn try_fill_bytes(
&mut self,
dst: &mut [u8],
) -> Result<(), <R as TryRngCore>::Error>
fn try_fill_bytes( &mut self, dst: &mut [u8], ) -> Result<(), <R as TryRngCore>::Error>
dest entirely with random data.Source§fn unwrap_mut(&mut self) -> UnwrapMut<'_, Self>
fn unwrap_mut(&mut self) -> UnwrapMut<'_, Self>
UnwrapMut wrapper.Source§fn read_adapter(&mut self) -> RngReadAdapter<'_, Self>where
Self: Sized,
fn read_adapter(&mut self) -> RngReadAdapter<'_, Self>where
Self: Sized,
RngCore to a RngReadAdapter.