MCPcopy Create free account
hub / github.com/QMHTMY/RustBook / iter

Function iter

publication/code/chapter04/stack.rs:144–158  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

142 }
143
144 fn iter() {
145 let mut s = Stack::new();
146 s.push(1); s.push(2); s.push(3);
147
148 let sum1 = s.iter().sum::<i32>();
149 let mut addend = 0;
150 for item in s.iter_mut() {
151 *item += 1;
152 addend += 1;
153 }
154
155 let sum2 = s.iter().sum::<i32>();
156 println!("{sum1} + {addend} = {sum2}");
157 assert_eq!(9, s.into_iter().sum::<i32>());
158 }
159}

Callers 1

mainFunction · 0.70

Calls 3

pushMethod · 0.45
iterMethod · 0.45
iter_mutMethod · 0.45

Tested by

no test coverage detected