特征"序列化"未实现<'_>


#[derive(serde::Serialize)]
struct IndexLink<'r>{
text: &'r str,
link: &'r str;
}
#[derive(serde::Serialize)]
struct IndexContext<'r> {
title: &'r str,
links: Vec<&'r IndexLink<&'r>>
}
#[get("/")]
pub fn index() -> Template {
Template::render("index", &IndexContext{
title : "My home on the web",
links: vec![IndexLink{text: "About", link: "/about"}, IndexLink{text: "RSS Feed", link: "/feed"}]
})
}

导致CCD_ 1。在渲染模板时,将IndexLinkvec添加到IndexContent的行中会出现错误。我这辈子一定做错了什么。

为什么会发生这种错误?

有问题的代码有多个语法错误。定义这些类型的有效方法似乎如下:

#[derive(serde::Serialize)]
struct IndexLink<'r>{
text: &'r str,
link: &'r str, // no semicolon inside struct definition
}
#[derive(serde::Serialize)]
struct IndexContext<'r> {
title: &'r str,
links: Vec<&'r IndexLink<'r>>, // lifetime parameter is just 'r, not &'r
}

最新更新