pub struct InMemoryStorage { /* private fields */ }Expand description
Storage backed by a map in memory (InMemoryStorage).
For tests and for environments without disk access. Content does not survive the process
(Storage::is_ephemeral is true); use LocalFileStorage to
persist. The store is unbounded, with no eviction. Keys follow the shipped backends’ rules:
slash runs collapse, leading and trailing slashes are stripped and .. segments are rejected.
use strands::storage::{InMemoryStorage, Storage};
let storage = InMemoryStorage::new();
let agent = storage.namespace("memory/agent")?;
agent.write("notes.md", b"dark mode").await?;
assert_eq!(storage.list("").await?, ["memory/agent/notes.md"]);
assert_eq!(agent.search("dark").await?[0].key, "notes.md");Implementations§
Source§impl InMemoryStorage
impl InMemoryStorage
Sourcepub fn with_config(config: InMemoryStorageConfig) -> Self
pub fn with_config(config: InMemoryStorageConfig) -> Self
An empty store with options.
Sourcepub fn namespace(&self, prefix: &str) -> Result<Self>
pub fn namespace(&self, prefix: &str) -> Result<Self>
A store scoped to prefix that shares this store’s entries and search strategy.
Unlike a NamespacedStorage view, the scoped store’s search
sees only the entries under the prefix and scores their keys without it, so a query does
not match every entry because it contains a word of the prefix. The shared strategy
receives the scoped store and keys relative to the prefix.
§Errors
Returns a StorageError when the prefix contains a backslash or a
.. segment.
Trait Implementations§
Source§impl Debug for InMemoryStorage
impl Debug for InMemoryStorage
Source§impl Default for InMemoryStorage
impl Default for InMemoryStorage
Source§impl Storage for InMemoryStorage
impl Storage for InMemoryStorage
Source§fn write<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
key: &'life1 str,
data: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn write<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
key: &'life1 str,
data: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Source§fn read<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn read<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
key. A no-op when the key does not exist. Read moreSource§fn list<'life0, 'life1, 'async_trait>(
&'life0 self,
prefix: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<String>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn list<'life0, 'life1, 'async_trait>(
&'life0 self,
prefix: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<String>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
prefix, sorted ascending. An empty prefix lists every key. Read moreSource§fn search<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 str,
) -> Pin<Box<dyn Future<Output = Option<Result<Vec<StorageSearchResult>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn search<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 str,
) -> Pin<Box<dyn Future<Output = Option<Result<Vec<StorageSearchResult>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn storage_type(&self) -> &str
fn storage_type(&self) -> &str
storageType. Read moreSource§fn is_ephemeral(&self) -> bool
fn is_ephemeral(&self) -> bool
Source§fn is_namespaced(&self) -> bool
fn is_namespaced(&self) -> bool
Auto Trait Implementations§
impl !RefUnwindSafe for InMemoryStorage
impl !UnwindSafe for InMemoryStorage
impl Freeze for InMemoryStorage
impl Send for InMemoryStorage
impl Sync for InMemoryStorage
impl Unpin for InMemoryStorage
impl UnsafeUnpin 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> 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 more