Optional bindings
Sometimes a binding might be optional, being behind a cargo feature or provided by an optional library. It will be useful to allow such bindings to be missing from the dependency graph, and detect whether such binding exists.
In Lockjaw a binding can be declared as optional by using the #[binds_option_of] method attribute in a #[module]
#[binds_option_of]
pub fn binds_option_of_string() -> String {}
The #[binds_option_of]
method should take no parameter and return the type T
to bind
as Option<T>
. This does not actually bind
the T
.
fn option_string(&self) -> Option<String>;
If T
is actually bound somewhere else, injecting Option<T>
will result in Some(T)
. Otherwise
it will be None
.