summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNadrieril2019-04-14 23:00:01 +0200
committerNadrieril2019-04-14 23:00:01 +0200
commit2954e502abb274b87ae3dbbb80ef523ebe602b28 (patch)
tree3f26b1f5b84af8669676b9e6dd75de6135579285
parent2e78bf6f5d7cf315aa1cc4fb7f828a6ee1f66b3f (diff)
improved_slice_patterns: doctests
Diffstat (limited to '')
-rw-r--r--improved_slice_patterns/Cargo.toml3
-rw-r--r--improved_slice_patterns/src/lib.rs40
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::<(), ()>(())
/// ```
///
///