DepBuilder

Trait DepBuilder 

Source
pub trait DepBuilder<R> {
    // Required methods
    fn build(
        registry: &Registry,
        ctor: &dyn TransientCtorFallibleDeps<R, Self>,
        _: SealToken,
    ) -> Result<R, ResolveError>
       where R: Sized;
    fn build_once(
        registry: &Registry,
        ctor: Box<dyn SingletonCtorFallibleDeps<R, Self>>,
        _: SealToken,
    ) -> Result<R, ResolveError>
       where R: Sized,
             Self: Sized;
    fn as_typeids(_: SealToken) -> Vec<(TypeId, &'static str)>;
}
Expand description

The DepBuilder trait is the key to specify a variable amount of dependencies in the Registry::with_deps call from Registry.

The trait is implemented by the DepBuilderImpl! macro for 0-ary, to 10-ary tuples (e.g., (T1,), (T1, T2), etc.), which allows these tuples to be passed as a single type parameter into Registry::with_deps.

This trait is sealed, meaning it cannot be implemented or called by any downstream crates.

Required Methods§

Source

fn build( registry: &Registry, ctor: &dyn TransientCtorFallibleDeps<R, Self>, _: SealToken, ) -> Result<R, ResolveError>
where R: Sized,

When implemented, this should validate that all dependencies which are part of Self exist to construct the type R. If the dependencies cannot be fulfilled, None must be returned.

If the dependencies can be fulfilled, they must be constructed as an N-ary tuple (same length and types as Self) and passed as the argument to ctor. ctor is a user provided constructor for the type R.

An implementation for tuples is provided by DepBuilderImpl!.

It’s advised to avoid manually implementing build.

Source

fn build_once( registry: &Registry, ctor: Box<dyn SingletonCtorFallibleDeps<R, Self>>, _: SealToken, ) -> Result<R, ResolveError>
where R: Sized, Self: Sized,

Similar to DepBuilder::build, except that it takes a boxed dyn FnOnce closure. This constructor is used for singletons.

Similarly to build, this is also implemented by DepBuilderImpl!.

It’s advised to avoid manually implementing build.

Source

fn as_typeids(_: SealToken) -> Vec<(TypeId, &'static str)>

Constructs a Vec of std::any::TypeIds from the types in Self. The resulting vector must have the same length as Self.

An implementation for tuples is provided by DepBuilderImpl!.

We advise against manually implementing as_typeids.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<R> DepBuilder<R> for ()
where R: Registerable,

Source§

fn build( _registry: &Registry, ctor: &dyn TransientCtorFallibleDeps<R, Self>, _: SealToken, ) -> Result<R, ResolveError>

Source§

fn build_once( _registry: &Registry, ctor: Box<dyn SingletonCtorFallibleDeps<R, Self>>, _: SealToken, ) -> Result<R, ResolveError>
where R: Sized, Self: Sized,

Source§

fn as_typeids(_: SealToken) -> Vec<(TypeId, &'static str)>

Source§

impl<R, T1> DepBuilder<R> for (T1,)
where R: Registerable, T1: Dep,

Source§

fn build( registry: &Registry, ctor: &dyn TransientCtorFallibleDeps<R, Self>, _: SealToken, ) -> Result<R, ResolveError>

Source§

fn build_once( registry: &Registry, ctor: Box<dyn SingletonCtorFallibleDeps<R, Self>>, _: SealToken, ) -> Result<R, ResolveError>
where R: Sized, Self: Sized,

Source§

fn as_typeids(_: SealToken) -> Vec<(TypeId, &'static str)>

Source§

impl<R, T1, T2> DepBuilder<R> for (T1, T2)
where R: Registerable, T1: Dep, T2: Dep,

Source§

fn build( registry: &Registry, ctor: &dyn TransientCtorFallibleDeps<R, Self>, _: SealToken, ) -> Result<R, ResolveError>

Source§

fn build_once( registry: &Registry, ctor: Box<dyn SingletonCtorFallibleDeps<R, Self>>, _: SealToken, ) -> Result<R, ResolveError>
where R: Sized, Self: Sized,

Source§

fn as_typeids(_: SealToken) -> Vec<(TypeId, &'static str)>

Source§

impl<R, T1, T2, T3> DepBuilder<R> for (T1, T2, T3)
where R: Registerable, T1: Dep, T2: Dep, T3: Dep,

Source§

fn build( registry: &Registry, ctor: &dyn TransientCtorFallibleDeps<R, Self>, _: SealToken, ) -> Result<R, ResolveError>

Source§

fn build_once( registry: &Registry, ctor: Box<dyn SingletonCtorFallibleDeps<R, Self>>, _: SealToken, ) -> Result<R, ResolveError>
where R: Sized, Self: Sized,

Source§

fn as_typeids(_: SealToken) -> Vec<(TypeId, &'static str)>

Source§

impl<R, T1, T2, T3, T4> DepBuilder<R> for (T1, T2, T3, T4)
where R: Registerable, T1: Dep, T2: Dep, T3: Dep, T4: Dep,

Source§

fn build( registry: &Registry, ctor: &dyn TransientCtorFallibleDeps<R, Self>, _: SealToken, ) -> Result<R, ResolveError>

Source§

fn build_once( registry: &Registry, ctor: Box<dyn SingletonCtorFallibleDeps<R, Self>>, _: SealToken, ) -> Result<R, ResolveError>
where R: Sized, Self: Sized,

Source§

fn as_typeids(_: SealToken) -> Vec<(TypeId, &'static str)>

Source§

impl<R, T1, T2, T3, T4, T5> DepBuilder<R> for (T1, T2, T3, T4, T5)
where R: Registerable, T1: Dep, T2: Dep, T3: Dep, T4: Dep, T5: Dep,

Source§

fn build( registry: &Registry, ctor: &dyn TransientCtorFallibleDeps<R, Self>, _: SealToken, ) -> Result<R, ResolveError>

Source§

fn build_once( registry: &Registry, ctor: Box<dyn SingletonCtorFallibleDeps<R, Self>>, _: SealToken, ) -> Result<R, ResolveError>
where R: Sized, Self: Sized,

Source§

fn as_typeids(_: SealToken) -> Vec<(TypeId, &'static str)>

Source§

impl<R, T1, T2, T3, T4, T5, T6> DepBuilder<R> for (T1, T2, T3, T4, T5, T6)
where R: Registerable, T1: Dep, T2: Dep, T3: Dep, T4: Dep, T5: Dep, T6: Dep,

Source§

fn build( registry: &Registry, ctor: &dyn TransientCtorFallibleDeps<R, Self>, _: SealToken, ) -> Result<R, ResolveError>

Source§

fn build_once( registry: &Registry, ctor: Box<dyn SingletonCtorFallibleDeps<R, Self>>, _: SealToken, ) -> Result<R, ResolveError>
where R: Sized, Self: Sized,

Source§

fn as_typeids(_: SealToken) -> Vec<(TypeId, &'static str)>

Source§

impl<R, T1, T2, T3, T4, T5, T6, T8> DepBuilder<R> for (T1, T2, T3, T4, T5, T6, T8)
where R: Registerable, T1: Dep, T2: Dep, T3: Dep, T4: Dep, T5: Dep, T6: Dep, T8: Dep,

Source§

fn build( registry: &Registry, ctor: &dyn TransientCtorFallibleDeps<R, Self>, _: SealToken, ) -> Result<R, ResolveError>

Source§

fn build_once( registry: &Registry, ctor: Box<dyn SingletonCtorFallibleDeps<R, Self>>, _: SealToken, ) -> Result<R, ResolveError>
where R: Sized, Self: Sized,

Source§

fn as_typeids(_: SealToken) -> Vec<(TypeId, &'static str)>

Source§

impl<R, T1, T2, T3, T4, T5, T6, T8, T9> DepBuilder<R> for (T1, T2, T3, T4, T5, T6, T8, T9)
where R: Registerable, T1: Dep, T2: Dep, T3: Dep, T4: Dep, T5: Dep, T6: Dep, T8: Dep, T9: Dep,

Source§

fn build( registry: &Registry, ctor: &dyn TransientCtorFallibleDeps<R, Self>, _: SealToken, ) -> Result<R, ResolveError>

Source§

fn build_once( registry: &Registry, ctor: Box<dyn SingletonCtorFallibleDeps<R, Self>>, _: SealToken, ) -> Result<R, ResolveError>
where R: Sized, Self: Sized,

Source§

fn as_typeids(_: SealToken) -> Vec<(TypeId, &'static str)>

Implementors§