#[derive(ResourceDependencies)]
{
// Attributes available to this derive:
#[may_fail]
#[old_style]
}
Expand description
This macro should be used to derive the
ResourceDependencies
trait for expressing dependencies between resources.
It takes a struct as input. The types of the fields of the struct should all match one of:
-
Arc<T>where T is a Resource. That resource will be a required dependency. -
Option<Arc<T>>where T is a Resource. That resource will be an optional dependency with the value being set no [None] if the dependency fails initialisation. -
Vec<Arc<dyn T>>where T is a trait that might be implemented by some resources. All of the resources that exist in the graph and implement that trait and declare that they do so in theirResourcedefinition (usingv1::resource) will be collected here.By default, if some resources matching the requested trait exist but fail initialisation, this will be considered an error: this set of dependencies will fail to construct and the error will be bubbled up. This mode is suitable for resources that wish to collect all available dependencies of a given type and not silently ignore a failing subset.
If a struct field of type [
Vec] is annotated with#[may_fail], then resources matching the requested trait exist but which fail initialisation will instead be dropped and a vector containing only the successful ones will be produced. This mode is suitable for resources that degrade well if some dependencies are not available (especially ones seeking just one working dependency resource from a set of possible ones.Note that in order to be selected for this, a Resource has to exist somewhere in the graph already, which means that somewhere it must be declared as a dependency under its concrete name. For this, a common expected pattern is that the Assembly’s top-level dependencies request it under its concrete type but otherwise do not make any use of it, enabling one or more resources elsewhere in the graph to discover it under its trait interface.
-
PhantomData<T>where T is a Resource. The resource will be made available to the assembly, but no dependency on it is introduced in the graph. The resource will be actually included in the assembly only if something depends on it in some other way.This is only useful if another resource depends upon
Tvia a trait that it exposes. In that case, thePhantomDatadependency serves to importTso that it can be discovered.
See
ResourceDependencies
for usage information.