-
-
Save RandyMcMillan/c8e30dddeaa782da597916c025c63829 to your computer and use it in GitHub Desktop.
posts_push.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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