diff --git a/src/libstd/str.rs b/src/libstd/str.rs index c3f79ff7139a6..cd0fc3e30d422 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -275,6 +275,27 @@ pub struct Chars<'a> { priv string: &'a str, } +impl<'a> Chars<'a> { + /** + * Returns the remaining string not yet iterated over. + * + * # Example + * + * Print the string `s` without the leading spaces + * (i.e. `"a string"`). + * + * ```rust + * let s = " a string"; + * let iter = s.chars(); + * for ch in iter { + * if ch != ' ' { break } + * } + * println!("{:s}", iter.remaining()); + * ``` + */ + pub fn remaining(&self) -> &'a str { self.string } +} + impl<'a> Iterator for Chars<'a> { #[inline] fn next(&mut self) -> Option {