我正在尝试做这个,但是不起作用:
fn foo() {
let v = b"Hello".to_vec();
let a = v.as_bytes();
}
我正在得到:
error[E0599]: no method named `as_bytes` found for struct `Vec<u8>` in the current scope
--> foo
|
26 | let a = v.as_bytes();
| ^^^^^^^^ method not found in `Vec<u8>`
vec<u8>
不能满足您的用例吗?而且这通常不被推荐,因为[u8]
在编译时需要显式静态大小。 - tieway59