Skip to content

Commit 6a35155

Browse files
authored
Merge pull request #334 from dtolnay/sizehint
Expose size_hint() for TokenStream's iterator
2 parents 6ed82b0 + 25a20e0 commit 6a35155

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,10 @@ pub mod token_stream {
12901290
fn next(&mut self) -> Option<TokenTree> {
12911291
self.inner.next()
12921292
}
1293+
1294+
fn size_hint(&self) -> (usize, Option<usize>) {
1295+
self.inner.size_hint()
1296+
}
12931297
}
12941298

12951299
impl Debug for IntoIter {

tests/test.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,13 @@ fn default_tokenstream_is_empty() {
547547
assert!(default_token_stream.is_empty());
548548
}
549549

550+
#[test]
551+
fn tokenstream_size_hint() {
552+
let tokens = "a b (c d) e".parse::<TokenStream>().unwrap();
553+
554+
assert_eq!(tokens.into_iter().size_hint(), (4, Some(4)));
555+
}
556+
550557
#[test]
551558
fn tuple_indexing() {
552559
// This behavior may change depending on https://github.com/rust-lang/rust/pull/71322

0 commit comments

Comments
 (0)