Skip to content

Commit

Permalink
Merge pull request #334 from dtolnay/sizehint
Browse files Browse the repository at this point in the history
Expose size_hint() for TokenStream's iterator
  • Loading branch information
dtolnay authored Jul 25, 2022
2 parents 6ed82b0 + 25a20e0 commit 6a35155
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,10 @@ pub mod token_stream {
fn next(&mut self) -> Option<TokenTree> {
self.inner.next()
}

fn size_hint(&self) -> (usize, Option<usize>) {
self.inner.size_hint()
}
}

impl Debug for IntoIter {
Expand Down
7 changes: 7 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,13 @@ fn default_tokenstream_is_empty() {
assert!(default_token_stream.is_empty());
}

#[test]
fn tokenstream_size_hint() {
let tokens = "a b (c d) e".parse::<TokenStream>().unwrap();

assert_eq!(tokens.into_iter().size_hint(), (4, Some(4)));
}

#[test]
fn tuple_indexing() {
// This behavior may change depending on https://github.com/rust-lang/rust/pull/71322
Expand Down

0 comments on commit 6a35155

Please sign in to comment.