use supply::prelude::*; struct Demo<'s> { s: &'s str, } impl<'r, 's> Provider<'r> for Demo<'s> { type Lifetimes = l!['s]; fn provide(&'r self, want: &mut dyn Want) { // The AddLt is to make it &'s str. want.provide_tag::<&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. demo.request::<&str>() }; // This is a reference to s as expected. assert_eq!(s_ref, Some("hello")); }