diff options
| author | Shamir Khodzha <khodzha.sh@gmail.com> | 2014-01-11 14:13:06 +0400 |
|---|---|---|
| committer | Shamir Khodzha <khodzha.sh@gmail.com> | 2014-01-11 22:38:43 +0400 |
| commit | 901dc2c15e08b6527f084c211d8d93448d997155 (patch) | |
| tree | ca6ce63e10f283f89bd23972596907e2e7c36af0 /src/libstd | |
| parent | f0541d5e947a22e6b897fcbe785f0c65a26f30cb (diff) | |
| download | rust-901dc2c15e08b6527f084c211d8d93448d997155.tar.gz rust-901dc2c15e08b6527f084c211d8d93448d997155.zip | |
added empty() to Peekable
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/iter.rs | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/libstd/iter.rs b/src/libstd/iter.rs index 2056f8b33ec..b9d7ee82851 100644 --- a/src/libstd/iter.rs +++ b/src/libstd/iter.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -1362,6 +1362,12 @@ impl<'a, A, T: Iterator<A>> Peekable<A, T> { None => None, } } + + /// Check whether peekable iterator is empty or not. + #[inline] + pub fn empty(&mut self) -> bool { + self.peek().is_some() + } } /// An iterator which rejects elements while `predicate` is true @@ -2923,4 +2929,12 @@ mod tests { ys.mut_iter().reverse_(); assert_eq!(ys, [5, 4, 3, 2, 1]); } + + fn test_peekable_empty() { + let a = [1]; + let mut it = a.iter().peekable(); + assert!( !it.empty() ); + it.next(); + assert!( it.empty() ); + } } |
