#[derive(ProviderSpec)]
{
// Attributes available to this derive:
#[provides]
#[named]
}
Expand description
Derive an inherent layer() (an id_effect::Layer providing the service) from
#[provides(Service)]. Re-exported by id_effect as ProviderSpecDerive.
Struct::layer::<E>() is a Layer<HCons<Service, HNil>, E> that needs nothing and never
fails. The service value comes from, in order of precedence:
#[provides(Service, with = <constructor>)]—|| expr, or a path such asSelf::buildcalled with no arguments. This is the recommended form: nofn new() -> Service(which tripsclippy::new_ret_no_self) is needed.Self::default()when the struct derivesDefault(the provider is its own service).Self::new()otherwise.
#[provides(Service, release = <finalizer>)] makes it an acquire_release layer whose
finalizer release(Arc<Service>) (an Effect<(), Never, HNil>) runs when the layer’s scope
closes. The 0.6 forms |deps: &Env| .. and #[named("..")] are compile errors.
ⓘ
#[derive(Clone)]
struct Counter(u32);
#[derive(ProviderSpecDerive)]
#[provides(Counter, with = || Counter(42))]
struct CounterLive;
let program = app().provide_layer(CounterLive::layer());