pub struct InMemoryStorage { /* private fields */ }Expand description
In-memory implementation of the Storage trait using a BTreeMap.
This implementation stores all data in memory and is useful for testing
or scenarios where durability is not required. Supports TTL-based
expiration via a configurable Clock.
Implementations§
Source§impl InMemoryStorage
impl InMemoryStorage
Sourcepub fn with_merge_operator(
merge_operator: Arc<dyn MergeOperator + Send + Sync>,
) -> Self
pub fn with_merge_operator( merge_operator: Arc<dyn MergeOperator + Send + Sync>, ) -> Self
Creates a new InMemoryStorage instance with an optional merge operator.
If a merge operator is provided, the merge method will use it to combine
existing values with new values. If no merge operator is provided, the
merge method will return an error.
Sourcepub fn with_clock(self, clock: Arc<dyn Clock>) -> Self
pub fn with_clock(self, clock: Arc<dyn Clock>) -> Self
Sets a custom clock for TTL expiration checks.
Sourcepub fn with_default_ttl(self, ttl: u64) -> Self
pub fn with_default_ttl(self, ttl: u64) -> Self
Sets the default TTL (in milliseconds) for records written with Ttl::Default.
Sourcepub fn with_deferred_durability(self) -> Self
pub fn with_deferred_durability(self) -> Self
Enables deferred durability mode.
When enabled, writes are not marked as durable until flush()
or flush_to() is called. This is useful for testing
read_durable behavior without depending on SlateDB internals.
Trait Implementations§
Source§impl Default for InMemoryStorage
impl Default for InMemoryStorage
Source§impl Storage for InMemoryStorage
impl Storage for InMemoryStorage
Source§fn put_with_options<'life0, 'async_trait>(
&'life0 self,
records: Vec<PutRecordOp>,
_options: WriteOptions,
) -> Pin<Box<dyn Future<Output = StorageResult<WriteResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn put_with_options<'life0, 'async_trait>(
&'life0 self,
records: Vec<PutRecordOp>,
_options: WriteOptions,
) -> Pin<Box<dyn Future<Output = StorageResult<WriteResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Writes a batch of records to the in-memory store.
All records are written atomically within a single write lock acquisition. For in-memory storage, write options are ignored since there is no durable storage to await.
Source§fn merge_with_options<'life0, 'async_trait>(
&'life0 self,
records: Vec<MergeRecordOp>,
_options: WriteOptions,
) -> Pin<Box<dyn Future<Output = StorageResult<WriteResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn merge_with_options<'life0, 'async_trait>(
&'life0 self,
records: Vec<MergeRecordOp>,
_options: WriteOptions,
) -> Pin<Box<dyn Future<Output = StorageResult<WriteResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Merges values for the given keys using the configured merge operator.
This method requires a merge operator to be configured during construction. For each record, it will:
- Get the existing value (if any), excluding expired entries
- Call the merge operator to combine existing and new values
- Put the merged result back with the new TTL
If no merge operator is configured, this method will return a
StorageError::Storage error.
Source§fn snapshot<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = StorageResult<Arc<dyn StorageSnapshot>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn snapshot<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = StorageResult<Arc<dyn StorageSnapshot>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Creates a point-in-time snapshot of the in-memory storage.
The snapshot provides a consistent read-only view of the database at the time the snapshot was created. Reads from the snapshot will not see any subsequent writes to the underlying storage. Expired entries are filtered at read time.
Source§fn apply_with_options<'life0, 'async_trait>(
&'life0 self,
records: Vec<RecordOp>,
_options: WriteOptions,
) -> Pin<Box<dyn Future<Output = StorageResult<WriteResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn apply_with_options<'life0, 'async_trait>(
&'life0 self,
records: Vec<RecordOp>,
_options: WriteOptions,
) -> Pin<Box<dyn Future<Output = StorageResult<WriteResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn subscribe_durable(&self) -> Receiver<u64>
fn subscribe_durable(&self) -> Receiver<u64>
Source§fn flush<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = StorageResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn flush<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = StorageResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn close<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = StorageResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn close<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = StorageResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn apply<'life0, 'async_trait>(
&'life0 self,
ops: Vec<RecordOp>,
) -> Pin<Box<dyn Future<Output = StorageResult<WriteResult>> + Send + 'async_trait>>where
Self: Sync + 'async_trait,
'life0: 'async_trait,
fn apply<'life0, 'async_trait>(
&'life0 self,
ops: Vec<RecordOp>,
) -> Pin<Box<dyn Future<Output = StorageResult<WriteResult>> + Send + 'async_trait>>where
Self: Sync + 'async_trait,
'life0: 'async_trait,
Source§fn put<'life0, 'async_trait>(
&'life0 self,
records: Vec<PutRecordOp>,
) -> Pin<Box<dyn Future<Output = StorageResult<WriteResult>> + Send + 'async_trait>>where
Self: Sync + 'async_trait,
'life0: 'async_trait,
fn put<'life0, 'async_trait>(
&'life0 self,
records: Vec<PutRecordOp>,
) -> Pin<Box<dyn Future<Output = StorageResult<WriteResult>> + Send + 'async_trait>>where
Self: Sync + 'async_trait,
'life0: 'async_trait,
Source§fn merge<'life0, 'async_trait>(
&'life0 self,
records: Vec<MergeRecordOp>,
) -> Pin<Box<dyn Future<Output = StorageResult<WriteResult>> + Send + 'async_trait>>where
Self: Sync + 'async_trait,
'life0: 'async_trait,
fn merge<'life0, 'async_trait>(
&'life0 self,
records: Vec<MergeRecordOp>,
) -> Pin<Box<dyn Future<Output = StorageResult<WriteResult>> + Send + 'async_trait>>where
Self: Sync + 'async_trait,
'life0: 'async_trait,
Source§impl StorageRead for InMemoryStorage
impl StorageRead for InMemoryStorage
Source§fn get<'life0, 'async_trait>(
&'life0 self,
key: Bytes,
) -> Pin<Box<dyn Future<Output = StorageResult<Option<Record>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get<'life0, 'async_trait>(
&'life0 self,
key: Bytes,
) -> Pin<Box<dyn Future<Output = StorageResult<Option<Record>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Retrieves a single record by key from the in-memory store.
Returns None if the key does not exist or has expired.
Source§fn scan_iter<'life0, 'async_trait>(
&'life0 self,
range: BytesRange,
) -> Pin<Box<dyn Future<Output = StorageResult<Box<dyn StorageIterator + Send + 'static>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn scan_iter<'life0, 'async_trait>(
&'life0 self,
range: BytesRange,
) -> Pin<Box<dyn Future<Output = StorageResult<Box<dyn StorageIterator + Send + 'static>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Auto Trait Implementations§
impl !Freeze for InMemoryStorage
impl !RefUnwindSafe for InMemoryStorage
impl Send for InMemoryStorage
impl Sync for InMemoryStorage
impl Unpin for InMemoryStorage
impl UnsafeUnpin for InMemoryStorage
impl !UnwindSafe for InMemoryStorage
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> 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> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);