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§
Sourcefn build(
registry: &Registry,
ctor: &dyn TransientCtorFallibleDeps<R, Self>,
_: SealToken,
) -> Result<R, ResolveError>where
R: Sized,
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.
Sourcefn build_once(
registry: &Registry,
ctor: Box<dyn SingletonCtorFallibleDeps<R, Self>>,
_: SealToken,
) -> Result<R, ResolveError>
fn build_once( registry: &Registry, ctor: Box<dyn SingletonCtorFallibleDeps<R, Self>>, _: SealToken, ) -> Result<R, ResolveError>
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.
Sourcefn as_typeids(_: SealToken) -> Vec<(TypeId, &'static str)>
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.