Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created November 10, 2024 21:33
Show Gist options
  • Save rust-play/8e520850a26313aa740b3b13d677612a to your computer and use it in GitHub Desktop.
Save rust-play/8e520850a26313aa740b3b13d677612a to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
use serde::{Deserialize, Serialize};
use serde_json::Result;
#[derive(Serialize, Deserialize)]
pub struct Post {
title: String,
created: String,
link: String,
description: String,
content: String,
author: String,
}
fn main() -> Result<()> {
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);
let json = serde_json::to_string(&posts)?;
dbg!(json);
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment