Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Container {
- elems: Vec<u8>,
- }
- impl Container {
- // Since we're just indexing, it would be nice to re-use CIter here
- fn iter_mut<'a>(&'a mut self) -> CIter<'a> {
- CIter {
- reference: self,
- position: 0,
- }
- }
- }
- struct CIter<'a> {
- reference: &'a mut Container,
- position: usize,
- }
- /*impl<'a> Iterator for CIter<'a> {
- type Item = &'a mut u8;
- fn next(&'a mut self) -> Option<&'a mut u8> {
- let item = self.reference.elems.get_mut(self.position);
- self.position += 1;
- item
- }
- }*/
- impl<'a> CIter<'a> {
- fn next(&'a mut self) -> Option<&'a mut u8> {
- let item = self.reference.elems.get_mut(self.position);
- self.position += 1;
- item
- }
- }
- fn main() {
- for elem in (Container { elems: vec![0, 1, 2, 3, 4, 5] }).iter_mut().next() {
- println!("{}", elem);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement