Skip to content

Commit

Permalink
Add remains, an optional alternative to rest. And fix a typo in t…
Browse files Browse the repository at this point in the history
…he `len` docs (#636)
  • Loading branch information
anyputer authored and arqunis committed Jun 29, 2019
1 parent 1527838 commit 3e15bb8
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/framework/standard/args.rs
Expand Up @@ -737,13 +737,21 @@ impl Args {
/// Starting from the offset, return the remainder of available arguments.
#[inline]
pub fn rest(&self) -> &str {
self.remains().unwrap_or_default()
}

/// Starting from the offset, return the remainder of available arguments.
///
/// Returns `None` if there are no remaining arguments.
#[inline]
pub fn remains(&self) -> Option<&str> {
if self.is_empty() {
return "";
return None;
}

let (start, _) = self.span();

&self.message[start..]
Some(&self.message[start..])
}

/// Return the full amount of recognised arguments.
Expand All @@ -752,7 +760,7 @@ impl Args {
/// # Note
///
/// The value returned is to be assumed to stay static.
/// However, if `find` was called previously, and was succesful, then the value is substracted by one.
/// However, if `find` was called previously, and was successful, then the value is substracted by one.
#[inline]
pub fn len(&self) -> usize {
self.args.len()
Expand Down

0 comments on commit 3e15bb8

Please sign in to comment.