X-Git-Url: https://piware.de/gitweb/?p=learn-rust.git;a=blobdiff_plain;f=src%2Flib.rs;fp=src%2Flib.rs;h=b7e5eb8f1df11116f8d94fd31fb1afe29491d087;hp=fe3b71b286640b29919d465a9fd25f55a002b42b;hb=105f3ee65d6d52bdeddda90afde8ebfcacc416e8;hpb=d65f952f600ad2d0828fd650829f6560404dca1c diff --git a/src/lib.rs b/src/lib.rs index fe3b71b..b7e5eb8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -85,3 +85,26 @@ where } } } + +pub struct Counter5 { + count: u32 +} + +impl Counter5 { + pub fn new() -> Counter5 { + Counter5 { count: 0 } + } +} + +impl Iterator for Counter5 { + type Item = u32; + + fn next(&mut self) -> Option { + if self.count < 5 { + self.count += 1; + Some(self.count) + } else { + None + } + } +}