我正在尝试编写一个函数,它接受 T: Into<Vec<u8>>
,但是当我尝试将一个 u8
数组传递给它时,即使 Vec
实现了 From<&'a [T]>>
,它也无法编译:
the trait `std::convert::From<&[u8; 5]>` is not implemented for `std::vec::Vec<u8>`
这是我的代码
fn is_hello<T: Into<Vec<u8>>>(s: T) {
let bytes = b"hello".to_vec();
assert_eq!(bytes, s.into());
}
fn main() {
is_hello(b"hello");
}