pub struct InMemorySessionService { /* private fields */ }Expand description
An in-memory SessionService. Thread-safe.
State keys are routed by prefix: app: keys are shared by every session of the app,
user: keys by every session of the user, and the rest belong to the session. temp:
keys in appended event deltas are never persisted; temp: keys in the initial state given
to create are kept in session state. Sessions handed out are copies of the service’s
record.
An event appended with an empty ID is given one:
use gadk_session::*;
use std::sync::Arc;
let svc: Arc<dyn SessionService> = Arc::new(InMemorySessionService::new());
let s = svc.create(CreateRequest { app_name: "app".into(), user_id: "u".into(), ..Default::default() }).await.unwrap();
let mut ev = Event::new(&gadk_platform::Platform::default(), "inv");
ev.id.clear();
svc.append_event(s.as_ref(), &mut ev).await.unwrap();
assert!(!ev.id.is_empty());Implementations§
Source§impl InMemorySessionService
impl InMemorySessionService
Sourcepub fn new() -> Self
pub fn new() -> Self
A new, empty service using Platform::default.
Sourcepub fn with_platform(platform: Platform) -> Self
pub fn with_platform(platform: Platform) -> Self
A new, empty service taking time and session/event IDs from platform.
Trait Implementations§
Source§impl Debug for InMemorySessionService
impl Debug for InMemorySessionService
Source§impl Default for InMemorySessionService
impl Default for InMemorySessionService
Source§impl SessionService for InMemorySessionService
impl SessionService for InMemorySessionService
Source§fn create<'life0, 'async_trait>(
&'life0 self,
req: CreateRequest,
) -> Pin<Box<dyn Future<Output = Result<Arc<dyn Session>, SessionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn create<'life0, 'async_trait>(
&'life0 self,
req: CreateRequest,
) -> Pin<Box<dyn Future<Output = Result<Arc<dyn Session>, SessionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Creates a session.
Source§fn get<'life0, 'async_trait>(
&'life0 self,
req: GetRequest,
) -> Pin<Box<dyn Future<Output = Result<Arc<dyn Session>, SessionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get<'life0, 'async_trait>(
&'life0 self,
req: GetRequest,
) -> Pin<Box<dyn Future<Output = Result<Arc<dyn Session>, SessionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Gets a session;
SessionError::NotFound if it does not exist (or belongs to
another user).Source§fn list<'life0, 'async_trait>(
&'life0 self,
req: ListRequest,
) -> Pin<Box<dyn Future<Output = Result<Vec<Arc<dyn Session>>, SessionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn list<'life0, 'async_trait>(
&'life0 self,
req: ListRequest,
) -> Pin<Box<dyn Future<Output = Result<Vec<Arc<dyn Session>>, SessionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Lists sessions; an empty result when there are none. Read more
Source§fn delete<'life0, 'async_trait>(
&'life0 self,
req: DeleteRequest,
) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn delete<'life0, 'async_trait>(
&'life0 self,
req: DeleteRequest,
) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Deletes a session; a no-op when it does not exist.
Source§fn append_event<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
session: &'life1 dyn Session,
event: &'life2 mut Event,
) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn append_event<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
session: &'life1 dyn Session,
event: &'life2 mut Event,
) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Auto Trait Implementations§
impl !Freeze for InMemorySessionService
impl !RefUnwindSafe for InMemorySessionService
impl !UnwindSafe for InMemorySessionService
impl Forget for InMemorySessionService
impl Move for InMemorySessionService
impl Send for InMemorySessionService
impl Sync for InMemorySessionService
impl Unpin for InMemorySessionService
impl UnsafeUnpin for InMemorySessionService
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
Mutably borrows from an owned value. Read more