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.
Trait Implementations§
Source§fn default() -> SharedState
fn default() -> SharedState
Auto Trait Implementations§
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<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
§impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
§impl<T> IntoAny for T
impl<T> IntoAny for T
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