supply 0.2.0

Provider API for arbitrary number of lifetimes.
Documentation
use super::{ErasedWantFor, Want, WantFor};
use crate::lt_list::LtList;
use crate::tag::{ReifySized, TagTypeId};

/// Want for a single value.
pub struct WantOne<L: LtList, T: ?Sized + ReifySized<L>>(Option<T::Reified>);

impl<T: ?Sized + ReifySized<L>, L: LtList> Default for WantOne<L, T> {
    fn default() -> Self {
        Self(None)
    }
}

impl<T: ?Sized + ReifySized<L>, L: LtList> WantOne<L, T> {
    /// Create want with a possibly set value.
    ///
    /// If `value` is `Some` then this want will always be satisfied.
    /// However, if a new value is provided it will replace the one given.
    pub fn new(value: Option<T::Reified>) -> Self {
        Self(value)
    }

    /// Convert into the inner option value.
    pub fn into_inner(self) -> Option<T::Reified> {
        self.0
    }
}

impl<T, L> Want<L> for WantOne<L, T>
where
    T: ?Sized + ReifySized<L>,
    L: LtList,
{
    fn try_for_id(&mut self, tag_type_id: TagTypeId<L>) -> Option<ErasedWantFor<'_, L>> {
        // To play nicely with the request combinators we need to only return
        // if we can be provided the type.
        if tag_type_id == TagTypeId::<L>::of::<T>() {
            // The caller will be able to use provide from the WantFor below.
            Some(ErasedWantFor::new::<T>(self))
        } else {
            None
        }
    }

    fn is_satisfied(&self) -> bool {
        // If the option has a value then the want is satisfied.
        self.0.is_some()
    }
}

impl<T: ?Sized + ReifySized<L>, L: LtList> WantFor<T::Lifetimes, T::UsedTag> for WantOne<L, T> {
    fn fulfill(&mut self, value: <T>::Reified) {
        // Stick the value in the option.
        self.0 = Some(value);
    }

    fn is_satisfied(&self) -> bool {
        self.0.is_some()
    }
}