Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: What's the type of a iterator over a Vec?
Ref:
Usually, you don't have to write out the full type of an iterator. But here, I need to.
This won't compile, because
fn fetch_next_field(pos: &mut Vec::Iter<'_, u8>) -> Option<String>
which yields the error message
error[E0107]: missing generics for struct `Vec`
help: add missing generic argument
|
| fn fetch_next_field(pos: &mut Vec<T>::Iter<'_, u8>) -> Option<String>{
| +++
Which seems reasonable enough. But if I put u8 in for T, the error message changes to
|
2 | fn fetch_next_field(pos: &mut Vec::Iter<', u8>) -> Option{
| ^^^^^^^^^^^^^^^^^^^^^
|
help: if there were a trait named Example
with associated type Iter
implemented for Vec<u8>
, you could use the fully-qualified path
|
2 - fn fetch_next_field(pos: &mut Vec::Iter<', u8>) -> Option{
2 + fn fetch_next_field(pos: &mut <Vec as Example>::Iter<'_, u8>) -> Option{
|
as if Vec doesn't implement Iter.
What is the correct type for that iterator?
4 posts - 3 participants
🏷️ Rust_feed