各位,我最近才接触到rust,现在想用rust写一个静态网站。现在我有一个非常基本的问题。代码如下:
pub struct Post {
title: String,
created: String,
link: String,
description: String,
content: String,
author: String,
}
fn main() {
let mut posts:Vec<Post> = Vec::new();
let post = Post {
title: "the title".to_string(),
created: "2021/06/24".to_string(),
link: "/2021/06/24/post".to_string(),
description: "description".to_string(),
content: "content".to_string(),
author: "jack".to_string(),
};
posts.push(post);
}
如何将帖子转换为 json,例如:
[{
"title": "the title",
"created": "2021/06/24",
"link": "/2021/06/24/post",
"description": "description",
"content": "content",
"author": "jack",
}]