I want to pass &[u8]
into a function that takes a u8
iterator:
fn f(words: &[u8]) {
g(words.iter())
}
fn g(words: impl Iterator<Item = u8>) {
//
}
The above doesn't work. It errors with:
error[E0271]: type mismatch resolving `<std::slice::Iter<'_, u8> as Iterator>::Item == u8`
--> src/lib.rs:3:5
|
3 | g(words.iter())
| ^ expected `u8`, found reference
...
6 | fn g(words: impl Iterator<Item = u8>) {
| --------- required by this bound in `g`
|
= note: expected type `u8`
found reference `&u8`
This is because the iterator is implemented as passing a reference, not the value. Is there a way to make this work without changing the signature of g
?