Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Foo(std::vec::Vec<u8>);
- struct Bar<'foo> {
- foo: &'foo Foo,
- }
- struct Baz<'foo> {
- foo: &'foo Foo,
- bar: Bar<'foo>,
- iter: std::slice::Iter<'foo, u8>,
- }
- impl<'foo> Iterator for Baz<'foo> {
- type Item = &'foo u8;
- fn next(&mut self) -> Option<&'foo u8> {
- self.iter.next()
- }
- }
- impl Foo {
- fn iter<'foo>(&'foo self) -> Baz<'foo> {
- let foo = self;
- let bar = Bar{
- foo: foo,
- };
- Baz {
- foo,
- bar,
- iter: bar.foo.0.iter(),
- }
- }
- }
- fn main() {
- let foo = Foo(vec![1,2,3]);
- for x in foo.iter() {
- println!("{}", x);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement