Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose size_hint() for TokenStream's iterator #334

Merged
merged 2 commits into from Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/lib.rs
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
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