From 3e15bb8ad240431d4351a1ab00d5aed249434fd5 Mon Sep 17 00:00:00 2001 From: hyarsan <32988993+hyarsan@users.noreply.github.com> Date: Sat, 29 Jun 2019 17:05:06 +0000 Subject: [PATCH] Add `remains`, an optional alternative to `rest`. And fix a typo in the `len` docs (#636) --- src/framework/standard/args.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/framework/standard/args.rs b/src/framework/standard/args.rs index d658fe9189e..356d5bfb3e3 100644 --- a/src/framework/standard/args.rs +++ b/src/framework/standard/args.rs @@ -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. @@ -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()