X-Git-Url: https://piware.de/gitweb/?p=learn-rust.git;a=blobdiff_plain;f=src%2Flib.rs;h=b7e5eb8f1df11116f8d94fd31fb1afe29491d087;hp=fe3b71b286640b29919d465a9fd25f55a002b42b;hb=7ed2d982ac15df78e;hpb=b6a408eb8944df04d6c6e876a9a00f6c425f47f1 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 + } + } +}