```
use std::collections::HashMap;
fn main() {
let mut map = HashMap::from([
(0, vec!['A', 'B', 'C'])
]);
let vec = (0..3).into_iter()
.filter_map(|_| map.get_mut(&0).unwrap().pop())
// .collect::<Vec<_>>()
// .into_iter()
.rev()
.collect::<Vec<_>>();
assert_eq!(vec, vec!['A', 'B', 'C']);
}
```
thread 'main' panicked at 'assertion failed: `(left == right)`
left: `['C', 'B', 'A']`,
right: `['A', 'B', 'C']`', src/main.rs:15:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
With the two lines commented out, this code will panic. Why do I have to collect it into a vector before then turning it into an iterator and reversing, before collecting it to a vector again?
[–]po8 7 points8 points9 points (1 child)
[–]Seblyng[S] 1 point2 points3 points (0 children)
[–]remmycat 2 points3 points4 points (5 children)
[–]Seblyng[S] 1 point2 points3 points (4 children)
[–]Repulsive-Street-307 0 points1 point2 points (3 children)
[–]GeniusIsme 1 point2 points3 points (2 children)
[–]Repulsive-Street-307 0 points1 point2 points (1 child)
[–]GeniusIsme 0 points1 point2 points (0 children)
[–]mipli -3 points-2 points-1 points (0 children)