我有一个函数,其签名如下:
编译器似乎对
什么是将Vec传递到此接口的正确方法?
fn f(input: &mut Read, output: &mut Write)
我试图将Vec<u8>
既作为输入又作为输出:
let mut in: Vec<u8> = Vec::new();
let mut out: Vec<u8> = Vec::new();
f(&mut in[..], &mut out);
编译器似乎对
out
没有问题,但是我关于 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`
什么是将Vec传递到此接口的正确方法?
in
是一个保留关键字,不能用作变量名。 - undefined