Skip to content

Instantly share code, notes, and snippets.

Created June 16, 2015 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/10783e90287b7111c126 to your computer and use it in GitHub Desktop.
Save anonymous/10783e90287b7111c126 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
#![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