1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
// Copyright (c) Zefchain Labs, Inc. // SPDX-License-Identifier: Apache-2.0 use super::Persist; pub type Error = std::convert::Infallible; /// A dummy [`Persist`] implementation that doesn't persist anything, but holds the value /// in memory. #[derive(Default, derive_more::Deref)] pub struct Memory<T> { #[deref] value: T, } impl<T> Memory<T> { pub fn new(value: T) -> Self { Self { value } } } impl<T: Send> Persist for Memory<T> { type Error = Error; fn as_mut(&mut self) -> &mut T { &mut self.value } fn into_value(self) -> T { self.value } async fn persist(&mut self) -> Result<(), Error> { Ok(()) } }