[][src]Macro coi::container

macro_rules! container {
    (@registration $provider:ident scoped) => { ... };
    (@registration $provider:ident singleton) => { ... };
    (@registration $provider:ident normal) => { ... };
    (@registration $provider:ident) => { ... };
    (@line $builder:ident $key:ident $provider:ident $($call:ident)?) => { ... };
    ($($key:ident => $provider:ident $(. $call:ident)?),+) => { ... };
    ($($key:ident => $provider:ident $(. $call:ident)?,)+) => { ... };
}

A macro to simplify building of Containers.

It takes a list of key-value pairs, where the keys are converted to string keys, and the values are converted into registrations. Normal, singleton and scoped registrations are possible, with normal being the default:

use coi::{container, Inject};

trait Dep: Inject {}

#[derive(Inject)]
#[provides(dyn Dep with Impl)]
struct Impl;

impl Dep for Impl {}

let mut container = container! {
    dep => ImplProvider,
    normal_dep => ImplProvider.normal,
    singleton_dep => ImplProvider.singleton,
    scoped_dep => ImplProvider.scoped
};

For details on how each registration works, see coi::Registration