diff options
| author | bors <bors@rust-lang.org> | 2014-01-17 06:32:01 -0800 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-01-17 06:32:01 -0800 |
| commit | 1e1871f35eb83ae6a63952a145e5132deffded2c (patch) | |
| tree | 13c2e65b84ea234446447480f5fbfa59b5e86f64 /src/libstd | |
| parent | 7d75bbf50ddcf076d3cf294501346293060c5735 (diff) | |
| parent | 4993c7c804398bd149a1831f55b8180acc83e1da (diff) | |
| download | rust-1e1871f35eb83ae6a63952a145e5132deffded2c.tar.gz rust-1e1871f35eb83ae6a63952a145e5132deffded2c.zip | |
auto merge of #11479 : khodzha/rust/peekable_empty, r=brson
to fix https://github.com/mozilla/rust/issues/11218
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..fcf0f4f2444 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 is_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_is_empty() { + let a = [1]; + let mut it = a.iter().peekable(); + assert!( !it.is_empty() ); + it.next(); + assert!( it.is_empty() ); + } } |
