Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![feature(generic_associated_types)]
- trait MyFn {
- type Output<'a>; // <-- we added <'a> to make it generic
- fn call(&self) -> Self::Output;
- }
- impl<T> MyFn for Baz<T> {
- type Output<'a> = &'a T;
- fn call(&self) -> Self::Output {
- &self.0
- }
- }
- struct Baz<T>(T);
- fn make_baz<T>(t: T) -> Box<for<'a> MyFn<Output<'a> = &'a T>> {
- Box::new(Baz(t))
- }
- fn main() {
- let outside = {
- let s = "hi".to_string();
- let baz = make_baz(&s); // <-- NOW BORROWED!
- println!("{}", baz.call()); // works
- baz
- };
- println!("{}", outside.call()); // doesn't work!
- }
Add Comment
Please, Sign In to add comment