Created
June 16, 2015 13:19
-
-
Save anonymous/10783e90287b7111c126 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![allow(unused)] | |
#[derive(Debug)] | |
struct IntegerArrayBag<'a> { | |
arr: &'a [i32], | |
idx: usize, | |
} | |
impl<'a> IntegerArrayBag<'a> { | |
fn len(&self) -> usize { | |
self.arr.len() | |
} | |
fn get(&self, idx: usize) -> Option<&'a i32> { | |
if self.arr.len() > idx { | |
Some(&self.arr[idx]) | |
} else { | |
None | |
} | |
} | |
} | |
impl<'a> Iterator for IntegerArrayBag<'a> { | |
type Item = &'a i32; | |
fn next(&mut self) -> Option<&'a i32> { | |
let idx = self.idx; | |
self.idx += 1; | |
self.get(idx) | |
} | |
} | |
fn main() { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment