1
use serde::{Deserialize, Serialize};
2

            
3
11
#[derive(Debug, Serialize, Deserialize)]
4
struct BlogPost {
5
    id: u64,
6
    title: String,
7
    body: String,
8
    #[serde(default)]
9
    previous_in_series: Option<u64>,
10
    category: Category,
11
}
12

            
13
4
#[derive(Debug, Serialize, Deserialize)]
14
enum Category {
15
    Rust,
16
    Custom(String),
17
}
18

            
19
1
fn main() {
20
1
    let posts: Vec<BlogPost> =
21
1
        rsn::from_str(include_str!("./basic.rsn")).expect("valid rsn in basic.rsn");
22
1

            
23
1
    println!("Loaded blog posts: {posts:?}");
24
1

            
25
1
    let compact = rsn::to_string(&posts).expect("no errors");
26
1
    println!("Compact form:\n{compact}");
27
1
    let pretty = rsn::to_string_pretty(&posts).expect("no errors");
28
1
    println!("Pretty form:\n{pretty}");
29
1
}
30

            
31
#[test]
32
1
fn runs() {
33
1
    main();
34
1
}