尝试执行以下操作时遇到类型错误:
use kuchiki::parse_html;
use kuchiki::traits::*;
fn main() {
let data = r#"<!DOCTYPE html>
<html>
<body>
test
</body>
</html>"#;
let dom = parse_html()
.from_utf8()
.from_iter(data.as_bytes());
}
错误是:
error[E0271]: type mismatch resolving `<tendril::fmt::Bytes as tendril::fmt::SliceFormat>::Slice == u8`
--> src/main.rs:13:10
|
13 | .from_iter(data.as_bytes());
| ^^^^^^^^^ expected slice, found u8
|
= note: expected type `[u8]`
found type `u8`
= note: required because of the requirements on the impl of `std::convert::Into<tendril::tendril::Tendril<tendril::fmt::Bytes>>` for `&u8`
data.as_bytes()
返回对字节切片 ( &[u8]
) 的引用,所以我对found u8
来自哪里感到困惑。我该如何纠正这个错误?
有问题的方法的文档在这里。