supply 0.1.0

Provider API for arbitrary number of lifetimes.
Documentation
use supply::tag::AddLt;
use supply::{Lt1, Provider, RequestExt, Want};

struct Demo<'s> {
    s: &'s str,
}

impl<'s> Provider for Demo<'s> {
    type Lifetimes = Lt1<'s>;

    fn provide<'r>(&'r self, want: &mut dyn Want<'r, Lt1<'s>>) {
        // The AddLt is to make it &'s str.
        want.provide_tag::<AddLt<&AddLt<str>>>(self.s);
    }
}

#[test]
fn example() {
    // A string that lives longer than demo.
    let s = String::from("hello");

    let s_ref = {
        let demo = Demo { s: &s };

        // The AddLt here bumps the lifetime of the &str to
        // be &'s str instead of &'r str. That way we can return
        // the borrow from this scope.
        <AddLt<&AddLt<str>>>::request(&demo)
    };

    // This is a reference to s as expected.
    assert_eq!(s_ref, Some("hello"));
}