From 350d69f76a41a8a1485c91bc051c1e03a339a087 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Wed, 18 May 2022 18:36:31 +0300 Subject: renname container to set to reduce confusion with other example Sponsored-by: author --- src/main.rs | 20 ++++++++++---------- 1 file 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 = Container::new(); + let mut cont: Set = Set::new(); cont.push(42); for v in cont.iter() { println!("{}", v); } } -struct Container { +struct Set { items: Vec, } -impl Container { +impl Set { fn new() -> Self { Self { items: vec![] } } @@ -19,23 +19,23 @@ impl Container { self.items.push(item); } - fn iter(&self) -> ContainerItems { - ContainerItems::new(self) + fn iter(&self) -> Items { + Items::new(self) } } -struct ContainerItems<'a, T> { - cont: &'a Container, +struct Items<'a, T> { + cont: &'a Set, next: Option, } -impl<'a, T> ContainerItems<'a, T> { - fn new(cont: &'a Container) -> Self { +impl<'a, T> Items<'a, T> { + fn new(cont: &'a Set) -> 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 { -- cgit v1.2.1