我正在使用Rocket,我正在尝试创建一个Layout
结构。我已经实现serde::Serialize
了,因为文档说静态方法Template::render
的第二个参数接受一个实现的结构Serialize
:
struct Layout {
data: String,
second: String,
}
impl Layout {
fn new(data: String, second: String) -> Layout {
Layout { data, second }
}
fn render(&self) -> Template {
Template::render("Layout", &self)
}
}
impl Serialize for Layout {
fn serialize<S>(&self, serialize: S) -> Result<S::Ok, S::Error>
where S: Serializer
{
let mut state = serializer.serialize_struct("Layout", 2);
state.serialize_field("data", &self.data)?;
state.serialize_field("second", &self.data)?;
state.end()
}
}
我得到错误
the trait `serde::ser::Serialize` is not implemented for `layout::Layout`
我做错了什么?