Struct async_injector::Ref [−][src]
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
Read the synchronized variable.
Examples
use std::error::Error;
#[derive(Clone)]
struct Database;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let injector = async_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());
Ok(())
}
Load the synchronized variable. This clones the underlying value if it has been set.
Examples
use std::error::Error;
#[derive(Clone)]
struct Database;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let injector = async_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());
Ok(())
}
Trait Implementations
Auto Trait Implementations
impl<T> !RefUnwindSafe for Ref<T>
impl<T> !UnwindSafe for Ref<T>
Blanket Implementations
Mutably borrows from an owned value. Read more