pub trait Provider<'cx, S: Service>: 'cx {
fn provide(&'cx self, cx: &'cx Context<'_>) -> S::Output<'cx>;
}Expand description
A can construct a Service which references objects either inside itself or the provided
Context.
Any type implementing the appropriate Fn trait can be used as a provider:
// A service providing a random number
#[derive(Service)]
struct Random(u64);
// Create a context and bind Random to a provider
let mut cx = Context::new();
cx.bind_fn::<Random>(|_cx: &Context| Random(rand::random()));
// Print a random number
println!("{}", cx.resolve::<Random>().0);