pub struct StateStore {
pub base_path: PathBuf,
}Expand description
A filesystem-based persistent state store.
Files are organized as <base_path>/<category>/<name>.md or
<base_path>/<category>/<name>.json.
Fields§
§base_path: PathBufRoot directory for all state files.
Implementations§
Source§impl StateStore
impl StateStore
Sourcepub fn new(base_path: PathBuf) -> Result<Self>
pub fn new(base_path: PathBuf) -> Result<Self>
Creates a new state store, initializing the directory if needed.
§Example
use oxios_kernel::state_store::StateStore;
use std::path::PathBuf;
let store = StateStore::new(PathBuf::from("/tmp/oxios-state")).unwrap();Sourcepub async fn save_markdown(
&self,
category: &str,
name: &str,
content: &str,
) -> Result<()>
pub async fn save_markdown( &self, category: &str, name: &str, content: &str, ) -> Result<()>
Save a markdown file under the given category.
Sourcepub async fn load_markdown(
&self,
category: &str,
name: &str,
) -> Result<Option<String>>
pub async fn load_markdown( &self, category: &str, name: &str, ) -> Result<Option<String>>
Load a markdown file from the given category.
Sourcepub async fn list_category(&self, category: &str) -> Result<Vec<String>>
pub async fn list_category(&self, category: &str) -> Result<Vec<String>>
List all markdown files in a category (names without extension).
Sourcepub async fn save_json<T: Serialize>(
&self,
category: &str,
name: &str,
data: &T,
) -> Result<()>
pub async fn save_json<T: Serialize>( &self, category: &str, name: &str, data: &T, ) -> Result<()>
Save a serializable value as JSON under the given category.
Source§impl StateStore
impl StateStore
Sourcepub async fn save_session(&self, session: &Session) -> Result<()>
pub async fn save_session(&self, session: &Session) -> Result<()>
Saves a session to the sessions category.
Sourcepub async fn save_session_with_prune(
&self,
session: &Session,
prune_config: &PruneConfig,
) -> Result<()>
pub async fn save_session_with_prune( &self, session: &Session, prune_config: &PruneConfig, ) -> Result<()>
Saves a session and then runs pruning if auto_prune is enabled.
Sourcepub async fn load_session(
&self,
session_id: &SessionId,
) -> Result<Option<Session>>
pub async fn load_session( &self, session_id: &SessionId, ) -> Result<Option<Session>>
Loads a session by ID.
Sourcepub async fn list_sessions(&self) -> Result<Vec<SessionSummary>>
pub async fn list_sessions(&self) -> Result<Vec<SessionSummary>>
Lists all sessions (sorted by updated_at descending).
Sourcepub async fn delete_session(&self, session_id: &SessionId) -> Result<bool>
pub async fn delete_session(&self, session_id: &SessionId) -> Result<bool>
Deletes a session by ID.
Sourcepub async fn get_or_create_session(
&self,
user_id: &str,
session_id: Option<&SessionId>,
) -> Result<Session>
pub async fn get_or_create_session( &self, user_id: &str, session_id: Option<&SessionId>, ) -> Result<Session>
Gets or creates a session for a user, initializing with the given session ID.
Sourcepub async fn update_session(&self, session: &Session) -> Result<()>
pub async fn update_session(&self, session: &Session) -> Result<()>
Updates an existing session, saving it to disk.
Sourcepub async fn prune_sessions(&self, config: &PruneConfig) -> Result<usize>
pub async fn prune_sessions(&self, config: &PruneConfig) -> Result<usize>
Prune sessions based on configuration.
Removes sessions that exceed TTL or exceed the maximum count. Returns the number of sessions pruned.
Trait Implementations§
Source§impl AuditPersistence for StateStore
impl AuditPersistence for StateStore
Source§impl Clone for StateStore
impl Clone for StateStore
Source§fn clone(&self) -> StateStore
fn clone(&self) -> StateStore
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for StateStore
impl Debug for StateStore
Source§impl MemoryStorage for StateStore
impl MemoryStorage for StateStore
Source§fn save_json_value<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
c: &'life1 str,
k: &'life2 str,
v: &'life3 Value,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn save_json_value<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
c: &'life1 str,
k: &'life2 str,
v: &'life3 Value,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Source§fn load_json_value<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
c: &'life1 str,
k: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<Option<Value>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn load_json_value<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
c: &'life1 str,
k: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<Option<Value>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Source§fn list_category<'life0, 'life1, 'async_trait>(
&'life0 self,
category: &'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_category<'life0, 'life1, 'async_trait>(
&'life0 self,
category: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<String>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn delete_file<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
category: &'life1 str,
key: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn delete_file<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
category: &'life1 str,
key: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Auto Trait Implementations§
impl Freeze for StateStore
impl RefUnwindSafe for StateStore
impl Send for StateStore
impl Sync for StateStore
impl Unpin for StateStore
impl UnsafeUnpin for StateStore
impl UnwindSafe for StateStore
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
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 moreimpl<T> MaybeSendSync for T
Source§impl<S> MemoryStorageExt for Swhere
S: MemoryStorage + ?Sized,
impl<S> MemoryStorageExt for Swhere
S: MemoryStorage + ?Sized,
Source§fn save_json<'life0, 'life1, 'life2, 'life3, 'async_trait, T>(
&'life0 self,
category: &'life1 str,
key: &'life2 str,
value: &'life3 T,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
fn save_json<'life0, 'life1, 'life2, 'life3, 'async_trait, T>( &'life0 self, category: &'life1 str, key: &'life2 str, value: &'life3 T, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
Source§fn load_json<'life0, 'life1, 'life2, 'async_trait, T>(
&'life0 self,
category: &'life1 str,
key: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<Option<T>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
T: 'async_trait + DeserializeOwned + Send,
Self: Sync + 'async_trait,
fn load_json<'life0, 'life1, 'life2, 'async_trait, T>(
&'life0 self,
category: &'life1 str,
key: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<Option<T>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
T: 'async_trait + DeserializeOwned + Send,
Self: Sync + 'async_trait,
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> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> 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.