diff options
Diffstat (limited to 'improved_slice_patterns')
-rw-r--r-- | improved_slice_patterns/Cargo.toml | 3 | ||||
-rw-r--r-- | improved_slice_patterns/src/lib.rs | 40 |
2 files changed, 26 insertions, 17 deletions
diff --git a/improved_slice_patterns/Cargo.toml b/improved_slice_patterns/Cargo.toml index f4d9577..f2b7d8e 100644 --- a/improved_slice_patterns/Cargo.toml +++ b/improved_slice_patterns/Cargo.toml @@ -4,6 +4,3 @@ version = "0.1.0" authors = ["Nadrieril <nadrieril@users.noreply.github.com>"] license = "BSD-2-Clause" edition = "2018" - -[lib] -doctest = false diff --git a/improved_slice_patterns/src/lib.rs b/improved_slice_patterns/src/lib.rs index 1842599..726b57a 100644 --- a/improved_slice_patterns/src/lib.rs +++ b/improved_slice_patterns/src/lib.rs @@ -10,15 +10,22 @@ /// /// Example: /// ``` -/// let vec = vec![Some(1), Some(2), None]; +/// use improved_slice_patterns::destructure_iter; /// -/// destructure_iter!(vec.into_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))); +/// +/// # Ok::<(), ()>(()) /// ``` /// /// @@ -115,19 +122,24 @@ macro_rules! destructure_iter { /// /// Example: /// ``` -/// let vec = vec![Some(1), Some(2), None]; +/// #![feature(slice_patterns)] +/// use improved_slice_patterns::match_vec; /// -/// match_vec!(vec; -/// [Some(x), y.., z] => { -/// // x: usize -/// // y: impl Iterator<Option<usize>> -/// // z: Option<usize> -/// } -/// [x, Some(0)] => { -/// // x: Option<usize> +/// let vec = vec![Some(1), Some(2), Some(3), None]; +/// +/// let res = match_vec!(vec; +/// [Some(_), y.., None] => { +/// y.collect::<Vec<_>>() /// }, -/// [..] => { } -/// ) +/// [None, None] => { +/// vec![] +/// }, +/// [..] => vec![] +/// ); +/// +/// assert_eq!(res, Some(vec![Some(2), Some(3)])); +/// +/// # Ok::<(), ()>(()) /// ``` /// /// |