pub trait DepBuilder<R> {
// Required methods
fn build(
registry: &Registry,
ctor: fn(_: Self) -> R,
_: SealToken,
) -> Option<R>
where R: Sized;
fn as_typeids(_: SealToken) -> Vec<TypeId>;
}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: fn(_: Self) -> R, _: SealToken) -> Option<R>where
R: Sized,
fn build(registry: &Registry, ctor: fn(_: Self) -> R, _: SealToken) -> Option<R>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!.
We advise against manually implementing build.
sourcefn as_typeids(_: SealToken) -> Vec<TypeId>
fn as_typeids(_: SealToken) -> Vec<TypeId>
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.