I have a function with the following signature:
fn f(input: &mut Read, output: &mut Write)
And I try to pass Vec<u8>
s as both input and output:
let mut in: Vec<u8> = Vec::new();
let mut out: Vec<u8> = Vec::new();
f(&mut in[..], &mut out);
The compiler seems to be fine with out
, but I get errors about in
:
error[E0277]: the trait bound `[u8]: std::io::Read` is not satisfied
--> src/crypto.rs:109:25
|
109 | f(&mut in[..], &mut out);
^^^^^^^^^^^ the trait `std::io::Read` is not implemented for `[u8]`
|
= help: the following implementations were found:
<&'a [u8] as std::io::Read>
= note: required for the cast to the object type `std::io::Read`
error[E0277]: the trait bound `[u8]: std::marker::Sized` is not satisfied
--> src/crypto.rs:109:25
|
109 | f(&mut in[..], &mut out);
| ^^^^^^^^^^^ `[u8]` does not have a constant size known at compile-time
|
= help: the trait `std::marker::Sized` is not implemented for `[u8]`
= note: required for the cast to the object type `std::io::Read`
What is the right way to pass a Vec into such interface?