aboutsummaryrefslogtreecommitdiff
path: root/src/framework
diff options
context:
space:
mode:
authoracdenisSK <[email protected]>2017-12-24 12:41:05 +0100
committeracdenisSK <[email protected]>2017-12-24 12:42:50 +0100
commit032c5a75620c3ff185a749113d93fb3051b38acb (patch)
tree99daef3beaae70f7ebed49b97c21b7cb3da83bf7 /src/framework
parentFix `multiple_quoted` (#241) (diff)
downloadserenity-032c5a75620c3ff185a749113d93fb3051b38acb.tar.xz
serenity-032c5a75620c3ff185a749113d93fb3051b38acb.zip
Add `iter_quoted`
Diffstat (limited to 'src/framework')
-rw-r--r--src/framework/standard/args.rs38
1 files changed, 28 insertions, 10 deletions
diff --git a/src/framework/standard/args.rs b/src/framework/standard/args.rs
index 33ec9fe..87cc0a5 100644
--- a/src/framework/standard/args.rs
+++ b/src/framework/standard/args.rs
@@ -61,7 +61,6 @@ fn parse_quotes<T: FromStr>(s: &mut String, delimiters: &[String]) -> Result<T,
// Fall back to `parse` if there're no quotes at the start
// or if there is no closing one as well.
if let Some(mut pos) = second_quote_occurence(s) {
-
if s.starts_with('"') {
let res = (&s[1..pos]).parse::<T>().map_err(Error::Parse);
pos += '"'.len_utf8();
@@ -76,14 +75,11 @@ fn parse_quotes<T: FromStr>(s: &mut String, delimiters: &[String]) -> Result<T,
s.drain(..pos);
- res
- } else {
- return parse::<T>(s, delimiters)
+ return res;
}
-
- } else {
- return parse::<T>(s, delimiters)
}
+
+ parse::<T>(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::<T>::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::<i32>().map(|n| n.unwrap().pow(2)).collect::<Vec<_>>(), [4, 25]);
+ /// assert!(args.is_empty());
+ /// ```
+ ///
+ /// [`iter`]: #method.iter
+ pub fn iter_quoted<T: FromStr>(&mut self) -> IterQuoted<T>
+ 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::<i32>().map(|num| num.unwrap().pow(2)).collect::<Vec<_>>(), [9, 16]);
/// assert!(args.is_empty());
/// ```
- pub fn iter<T: FromStr>(&mut self) -> Iter<T> where T::Err: StdError {
+ pub fn iter<T: FromStr>(&mut self) -> Iter<T>
+ 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<T>,