Struct test_harness::SharedState
source · pub struct SharedState(_);
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>where
F: FnOnce() -> Fut,
Fut: Future<Output = Result<T, Error>>,
T: Send + Sync + 'static,
pub async fn get_or_insert_with<F, Fut, T>( &self, key: &str, inserter: F ) -> Result<Arc<T>, Error>where F: FnOnce() -> Fut, Fut: Future<Output = Result<T, Error>>, T: Send + Sync + 'static,
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.