diff options
author | Lars Wirzenius <liw@sequoia-pgp.org> | 2022-05-18 18:36:31 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@sequoia-pgp.org> | 2022-05-18 18:36:31 +0300 |
commit | 350d69f76a41a8a1485c91bc051c1e03a339a087 (patch) | |
tree | acef97d88784d61afbace523f0a9b80f51a79e85 | |
parent | dd4f42323b77b7ad5e1c8ad4d27a09b21a2cf2b3 (diff) | |
download | iter-350d69f76a41a8a1485c91bc051c1e03a339a087.tar.gz |
Sponsored-by: author
-rw-r--r-- | src/main.rs | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/main.rs b/src/main.rs index 170dad0..12092d6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,16 +1,16 @@ fn main() { - let mut cont: Container<usize> = Container::new(); + let mut cont: Set<usize> = Set::new(); cont.push(42); for v in cont.iter() { println!("{}", v); } } -struct Container<T> { +struct Set<T> { items: Vec<T>, } -impl<T> Container<T> { +impl<T> Set<T> { fn new() -> Self { Self { items: vec![] } } @@ -19,23 +19,23 @@ impl<T> Container<T> { self.items.push(item); } - fn iter(&self) -> ContainerItems<T> { - ContainerItems::new(self) + fn iter(&self) -> Items<T> { + Items::new(self) } } -struct ContainerItems<'a, T> { - cont: &'a Container<T>, +struct Items<'a, T> { + cont: &'a Set<T>, next: Option<usize>, } -impl<'a, T> ContainerItems<'a, T> { - fn new(cont: &'a Container<T>) -> Self { +impl<'a, T> Items<'a, T> { + fn new(cont: &'a Set<T>) -> Self { Self { cont, next: Some(0) } } } -impl<'a, T> Iterator for ContainerItems<'a, T> { +impl<'a, T> Iterator for Items<'a, T> { type Item = &'a T; fn next(&mut self) -> Option<Self::Item> { |