Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. struct Foo(std::vec::Vec<u8>);
  2. struct Bar<'foo> {
  3. foo: &'foo Foo,
  4. }
  5.  
  6. struct Baz<'foo> {
  7. foo: &'foo Foo,
  8. bar: Bar<'foo>,
  9. iter: std::slice::Iter<'foo, u8>,
  10. }
  11.  
  12. impl<'foo> Iterator for Baz<'foo> {
  13. type Item = &'foo u8;
  14.  
  15. fn next(&mut self) -> Option<&'foo u8> {
  16. self.iter.next()
  17. }
  18. }
  19.  
  20. impl Foo {
  21. fn iter<'foo>(&'foo self) -> Baz<'foo> {
  22. let foo = self;
  23. let bar = Bar{
  24. foo: foo,
  25. };
  26. Baz {
  27. foo,
  28. bar,
  29. iter: bar.foo.0.iter(),
  30. }
  31. }
  32. }
  33.  
  34. fn main() {
  35. let foo = Foo(vec![1,2,3]);
  36. for x in foo.iter() {
  37. println!("{}", x);
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement