【发布时间】:2017-04-13 11:21:41
【问题描述】:
我正在尝试创建一个采用T: Into<Vec<u8>> 的函数,但是当我尝试将u8 的数组传递给它时,即使From<&'a [T]>> 由Vec 实现,它也无法编译:
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");
}
【问题讨论】:
标签: arrays generics rust traits