Implementing Iterator
Në shqip: Implementimi i Iterator-it
ShpjegimiSQ
Që tipi yt të punojë me for dhe me të gjitha metodat e iteratorëve, implemento Iterator: përcakto type Item dhe fn next(&mut self) -> Option<Self::Item>.
EnglishEN
For your type to work with for and all the iterator methods, implement Iterator: define type Item and fn next(&mut self) -> Option<Self::Item>.
Si ta mendosh
Si një makinë biletash që ti e programon vetë.
Lexoje në anglisht
Like a ticket machine you program yourself.
Shembull kodirust
struct Numrues(u32);
impl Iterator for Numrues {
type Item = u32;
fn next(&mut self) -> Option<u32> { self.0 += 1; (self.0 <= 3).then_some(self.0) }
}