pub struct SharedState(/* private fields */);
Implementations§
Sourcepub fn get<T: Send + Sync + 'static>(
&self,
key: &str,
) -> Option<Result<Arc<T>, Error>>
pub fn get<T: Send + Sync + 'static>( &self, key: &str, ) -> Option<Result<Arc<T>, Error>>
Returns None if no entry exists for key
. Returns Some(Err) if an entry exists for key
,
but is not of type T. Returns Some(Ok(Arc
Sourcepub fn try_insert<T: Send + Sync + 'static>(
&self,
key: &str,
val: T,
) -> Result<Arc<T>, Arc<dyn Any + Send + Sync + 'static>>
pub fn try_insert<T: Send + Sync + 'static>( &self, key: &str, val: T, ) -> Result<Arc<T>, Arc<dyn Any + Send + Sync + 'static>>
Insert val
at key
if key
is not yet occupied. If SharedState did not have an entry
for key
, returns Ok(Arc<the inserted val
>). Otherwise, does not insert val
and returns
Err(Arc
Sourcepub async fn get_or_insert_with<F, Fut, T>(
&self,
key: &str,
inserter: F,
) -> Result<Arc<T>, Error>
pub async fn get_or_insert_with<F, Fut, T>( &self, key: &str, inserter: F, ) -> Result<Arc<T>, Error>
This takes two type parameters, F and T. The inserter F is used in case key
is not yet
associated with an existing state value to create the value associated with key
. T is the
type of state expected to be associated with key
. After possibly inserting the state
associated with key
in the map, we dynamically cast key
s state into type T. Errors can
stem from inserter
failures, or existing types in the map not matching T.