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

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.