dfdi_core/
impls.rs

1use crate::{Context, Provider, Service};
2
3/// Allow `Fn` functions to act as providers.
4impl<'cx, F, S> Provider<'cx, S> for F
5where
6    F: Fn(&'cx Context, S::Argument<'_>) -> S::Output<'cx> + Send + Sync + 'cx,
7    S: Service,
8{
9    fn provide(&'cx self, cx: &'cx Context, arg: S::Argument<'_>) -> S::Output<'cx> {
10        (self)(cx, arg)
11    }
12}
13
14// Common service types
15
16impl<S: Service> Service for &'static S {
17    type Output<'cx> = &'cx S::Output<'cx>;
18    type Argument<'arg> = S::Argument<'arg>;
19}
20
21impl<S: Service> Service for &'static mut S {
22    type Output<'cx> = &'cx mut S::Output<'cx>;
23    type Argument<'arg> = S::Argument<'arg>;
24}