Struct async_injector::Ref
source · pub struct Ref<T>where
T: Clone + Any + Send + Sync,{ /* private fields */ }
Expand description
A variable allowing for the synchronized reading of avalue in the
Injector
.
This can be created through Injector::var or Injector::var_key.
Implementations§
source§impl<T> Ref<T>where
T: Clone + Any + Send + Sync,
impl<T> Ref<T>where T: Clone + Any + Send + Sync,
sourcepub async fn read(&self) -> Option<RefReadGuard<'_, T>>
pub async fn read(&self) -> Option<RefReadGuard<'_, T>>
Read the synchronized variable.
Examples
use async_injector::Injector;
#[derive(Clone)]
struct Database;
let injector = Injector::new();
let database = injector.var::<Database>().await;
assert!(database.read().await.is_none());
injector.update(Database).await;
assert!(database.read().await.is_some());
sourcepub async fn load(&self) -> Option<T>
pub async fn load(&self) -> Option<T>
Load the synchronized variable. This clones the underlying value if it has been set.
Examples
use async_injector::Injector;
#[derive(Clone)]
struct Database;
let injector = Injector::new();
let database = injector.var::<Database>().await;
assert!(database.load().await.is_none());
injector.update(Database).await;
assert!(database.load().await.is_some());