pub mod requests;
use ty_tag::lifetime_list::{LifetimeList, L0, L1};
use ty_tag::ReifySized;
use crate::want::WantOne;
use crate::{Provider, Want};
pub trait ProviderExt<'r>: Provider<'r> {
fn request<R>(&'r self) -> R::Output
where
R: Request<Self::Lifetimes>,
{
let mut want = R::Want::default();
self.provide(&mut want);
R::into_output(want)
}
fn request_mut<R>(&'r mut self) -> R::Output
where
R: Request<Self::Lifetimes>,
{
let mut want = R::Want::default();
self.provide_mut(&mut want);
R::into_output(want)
}
}
impl<'r, T: ?Sized + Provider<'r>> ProviderExt<'r> for T {}
pub trait Request<L: LifetimeList> {
type Want: Want<L> + Default;
type Output;
fn into_output(want: Self::Want) -> Self::Output;
}
impl<T: ReifySized<L0>> Request<L0> for T {
type Want = WantOne<L0, T::UsedTag>;
type Output = Option<T::Reified>;
fn into_output(want: Self::Want) -> Self::Output {
want.into_inner()
}
}
impl<'lt, Tail: LifetimeList, T: ReifySized<L1<'lt, Tail>>> Request<L1<'lt, Tail>> for T {
type Want = WantOne<L1<'lt, Tail>, T::UsedTag>;
type Output = Option<T::Reified>;
fn into_output(want: Self::Want) -> Self::Output {
want.into_inner()
}
}