【发布时间】:2016-05-19 16:35:21
【问题描述】:
我正在制作 Node 树。代码如下:
use std::option::Option;
use std::path;
#[derive(Debug)]
enum NodeType {
Binding((String, String)),
Header,
Include(path::Path),
Raw(String),
}
#[derive(Debug)]
pub struct Node {
node_type: NodeType,
}
impl Node {
fn new() -> Node {
Node { node_type: NodeType::Header }
}
}
当我编译这个时,我得到以下错误:
error[E0277]: the trait bound `[u8]: std::marker::Sized` is not satisfied in `std::path::Path`
--> src/main.rs:8:13
|
8 | Include(path::Path),
| ^^^^^^^^^^^ within `std::path::Path`, the trait `std::marker::Sized` is not implemented for `[u8]`
|
= note: `[u8]` does not have a constant size known at compile-time
= note: required because it appears within the type `std::path::Path`
= note: only the last field of a struct may have a dynamically sized type
我搜索了这个错误,但它似乎指的是Sized没有实现的类型。奇怪的是,错误输出显示[u8] 没有实现Sized,但我的代码中甚至没有u8。会是什么?
【问题讨论】:
-
样式点:空的
new可以通过实现Defaulttrait 的default方法更好地表达。它还使您的类型可以默认构造。
标签: rust