From 032c5a75620c3ff185a749113d93fb3051b38acb Mon Sep 17 00:00:00 2001 From: acdenisSK Date: Sun, 24 Dec 2017 12:41:05 +0100 Subject: [PATCH] Add `iter_quoted` --- src/framework/standard/args.rs | 38 +++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/src/framework/standard/args.rs b/src/framework/standard/args.rs index 33ec9fe2f85..87cc0a5d436 100644 --- a/src/framework/standard/args.rs +++ b/src/framework/standard/args.rs @@ -61,7 +61,6 @@ fn parse_quotes(s: &mut String, delimiters: &[String]) -> Result().map_err(Error::Parse); pos += '"'.len_utf8(); @@ -76,14 +75,11 @@ fn parse_quotes(s: &mut String, delimiters: &[String]) -> Result(s, delimiters) + return res; } - - } else { - return parse::(s, delimiters) } + + parse::(s, delimiters) } @@ -383,7 +379,7 @@ impl Args { /// /// # Examples /// - /// ```rust,ignore + /// ```rust /// use serenity::framework::standard::Args; /// /// let mut args = Args::new(r#""42" "69""#, &[" ".to_string()]); @@ -397,6 +393,25 @@ impl Args { IterQuoted::::new(&mut self).collect() } + /// Like [`iter`], but takes quotes into account + /// + /// # Examples + /// + /// ```rust + /// use serenity::framework::standard::Args; + /// + /// let mut args = Args::new(r#""2" "5""#, &[" ".to_string()]); + /// + /// assert_eq!(*args.iter_quoted::().map(|n| n.unwrap().pow(2)).collect::>(), [4, 25]); + /// assert!(args.is_empty()); + /// ``` + /// + /// [`iter`]: #method.iter + pub fn iter_quoted(&mut self) -> IterQuoted + where T::Err: StdError { + IterQuoted::new(self) + } + /// Empty outs the internal vector while parsing (if necessary) and returning them. /// /// # Examples @@ -425,7 +440,8 @@ impl Args { /// assert_eq!(*args.iter::().map(|num| num.unwrap().pow(2)).collect::>(), [9, 16]); /// assert!(args.is_empty()); /// ``` - pub fn iter(&mut self) -> Iter where T::Err: StdError { + pub fn iter(&mut self) -> Iter + where T::Err: StdError { Iter::new(self) } @@ -596,7 +612,9 @@ impl<'a, T: FromStr> Iterator for Iter<'a, T> where T::Err: StdError { } } -// Same as `Iter`, but considers quotes. +/// Same as [`Iter`], but considers quotes. +/// +/// [`Iter`]: #struct.Iter.html pub struct IterQuoted<'a, T: FromStr> where T::Err: StdError { args: &'a mut Args, _marker: PhantomData,