Skip to content

Commit

Permalink
update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Geal committed Jan 15, 2023
1 parent 51c4e03 commit 84615ac
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/multi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ where
}
}

/// Repeats the embedded parser and returns the results in a `Vec`.
/// Repeats the embedded parser and collects the results in a type implementing `Extend + Default`.
/// Fails if the amount of time the embedded parser is run is not
/// within the specified range.
/// # Arguments
Expand All @@ -1076,6 +1076,32 @@ where
/// assert_eq!(parser(""), Ok(("", vec![])));
/// assert_eq!(parser("abcabcabc"), Ok(("abc", vec!["abc", "abc"])));
/// ```
///
/// This is not limited to `Vec`:
///
/// /// ```rust
/// # #[macro_use] extern crate nom;
/// # use nom::{Err, error::ErrorKind, Needed, IResult};
/// use nom::multi::many;
/// use nom::bytes::complete::{tag, take_while};
/// use nom::sequence::{separated, terminated};
/// use nom::character::is_alphabetic;
///
/// use std::collectins::HashMap;
///
/// fn key_value(s: &str) -> IResult<&str, HashMap<&str, &str>> {
/// many(0.., terminated(
/// separated(
/// take_while(is_alphabetic),
/// tag("="),
/// take_while(is_alphabetic)
/// ),
/// tag(";")
/// ))(s)
/// }
///
/// assert_eq!(parser("a=b;c=d;"), Ok(("", HashMap::from([("a", "b"), ("c", "d")])));
/// ```
#[cfg(feature = "alloc")]
#[cfg_attr(feature = "docsrs", doc(cfg(feature = "alloc")))]
pub fn many<I, O, E, Collection, F, G>(
Expand Down

0 comments on commit 84615ac

Please sign in to comment.