[−][src]Macro improved_slice_patterns::destructure_iter
Destructure an iterator using the syntax of slice_patterns.
Wraps the match body in Some
if there was a match; returns
None
otherwise.
Contrary to slice_patterns, this allows moving out of the iterator.
A variable length pattern (x @ ..
) is only allowed as the last
pattern, unless the iterator is double-ended.
Example:
ⓘThis code runs with edition 2018
use improved_slice_patterns::destructure_iter; let vec = vec![Some(1), Some(2), Some(3), None]; let res = destructure_iter!(vec.into_iter(); [Some(x), y @ .., z] => { // x: usize // y: impl Iterator<Option<usize>> // z: Option<usize> (x, y.collect::<Vec<_>>(), z) } ); assert_eq!(res, Some((1, vec![Some(2), Some(3)], None)));