Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. struct Foo<'a> {
  2. r:&'a str,
  3. }
  4.  
  5. impl<'a> Foo<'a> {
  6. fn new(s: &'a str) -> Foo<'a> {
  7. Foo {
  8. r:s
  9. }
  10. }
  11. }
  12.  
  13. #[derive(Default)]
  14. struct Foos<'s> {
  15. r: Vec<&'s str>
  16. }
  17.  
  18. impl<'s> Foos<'s> {
  19. fn add<'a : 's>(&mut self, f: Foo<'a>) {
  20.  
  21. self.r.push(f.r);
  22. }
  23. }
  24.  
  25. fn main() {
  26. let mut foos = Foos::<'static>::default();
  27. foos.add(Foo::new("foo"));
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement