Rust

Crate root

Module
What utopia_di defines at its root.

Contents

use utopia_di::Container;
Rust
pub struct Container

Factories by id, built once and cached.

Rust
use std::sync::Arc;
use utopia_di::Container;

let parent = Arc::new(Container::new());
parent.set("config", &[], |_| Ok("prodConfig"));

let child = Container::with_parent(parent.clone());
child.set("service", &["config"], |deps| Ok(format!("service:{}", deps.get::<&str>(0)?)));

assert_eq!(*child.get::<String>("service")?, "service:prodConfig");
assert!(!parent.has("service"));
Also implements Debug.
use utopia_di::Dependencies;
Rust
pub struct Dependencies<'a>

The resolved dependencies a factory receives, in the order it declared them.

use utopia_di::Error;
Rust
pub enum Error

Why a dependency could not be resolved.

Rust
pub type Instance = Arc<dyn Any + Send + Sync>

A resolved dependency, shared by everything that resolves it.