From 2954e502abb274b87ae3dbbb80ef523ebe602b28 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 14 Apr 2019 23:00:01 +0200 Subject: improved_slice_patterns: doctests --- improved_slice_patterns/Cargo.toml | 3 --- 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 "] 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> /// // z: Option +/// (x, y.collect::>(), 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> -/// // z: Option -/// } -/// [x, Some(0)] => { -/// // x: Option +/// let vec = vec![Some(1), Some(2), Some(3), None]; +/// +/// let res = match_vec!(vec; +/// [Some(_), y.., None] => { +/// y.collect::>() /// }, -/// [..] => { } -/// ) +/// [None, None] => { +/// vec![] +/// }, +/// [..] => vec![] +/// ); +/// +/// assert_eq!(res, Some(vec![Some(2), Some(3)])); +/// +/// # Ok::<(), ()>(()) /// ``` /// /// -- cgit v1.2.3