fn foo(s: &[u8]) { ... }
fn main() {
let v = (0..128).collect();
foo(&v);
}
error[E0277]: the trait bound `[u8]: std::marker::Sized` is not satisfied
--> src/main.rs:4:9
|
4 | let v = (0..128).collect();
| ^ `[u8]` does not have a constant size known at compile-time
|
= help: the trait `std::marker::Sized` is not implemented for `[u8]`
= note: all local variables must have a statically known size
error[E0277]: the trait bound `[u8]: std::iter::FromIterator<{integer}>` is not satisfied
--> src/main.rs:4:22
|
4 | let v = (0..128).collect();
| ^^^^^^^ a collection of type `[u8]` cannot be built from an iterator over elements of type `{integer}`
|
= help: the trait `std::iter::FromIterator<{integer}>` is not implemented for `[u8]`
Iāve been using the Turbofish quite a few times recently. One example is testing functions which return an iterator, where for testing the complete output itās easiest to compare against a Vec (seems like type inference should work here, but it wasnāt); also in case the iterator output must be used multiple times and the iterator cannot be cloned then the output must be collected.