Macro runtime_injector::interface [−][src]
Marks a trait as being an interface for many other types. This means that a request for the given trait can resolve to any of the types indicated by this macro invocation.
With the arc
feature enabled, the trait must be a subtrait of Send
and
Sync
. This is necessary to allow the service pointers to be downcasted.
If the rc
feature is enabled, this is not required.
Example
use runtime_injector::interface; struct Bar; #[cfg(test)] struct MockBar; trait Foo: Send + Sync {} impl Foo for Bar {} #[cfg(test)] impl Foo for MockBar {} // Requests for `dyn Foo` can resolve to either `Bar` or, in a test run, // `MockBar`. Note that attributes are allowed on each of the listed types. interface!( Foo = [ Bar, #[cfg(test)] MockBar, ] );