Macro rudi::register_provider
source · macro_rules! register_provider { ($provider:expr) => { ... }; }
Available on crate feature
auto-register
only.Expand description
Register a Provider
that will be collected by auto_registered_providers
.
If you have:
- Enabled the
auto-register
feature (which is enabled by default). - Define
Provider
using the#[Singleton]
,#[Transient]
or#[SingleOwner]
macro. #[Singleton]
,#[Transient]
or#[SingleOwner]
does not use theauto_register = false
attribute.
Then you don’t need to use this macro to register Provider
.
But if you use function define a Provider
and you want to use auto-registration,
then you need to use this macro.
§Example
use rudi::{register_provider, singleton, Context, Provider};
fn foo() -> Provider<&'static str> {
singleton(|_| "Hello").into()
}
register_provider!(foo());
fn main() {
let mut cx = Context::auto_register();
assert!(cx.resolve_option::<&'static str>().is_some());
}