3 use serde::{Serialize, Deserialize};
5 #[derive(Serialize, Deserialize, Debug)]
12 #[derive(Serialize, Deserialize, Debug)]
19 type Contacts = Vec<Contact>;
21 fn build_contacts() -> Contacts {
23 Contact { name: "John".to_string(), phone: 12345, social: Social::Twitter("@the_john".to_string()) },
24 Contact { name: "Mary".to_string(), phone: 9876543, social: Social::ICQ(111234) },
25 Contact { name: "Jane".to_string(), phone: 555555, social: Social::Nothing },
29 fn create_contacts() -> Result<(), Box<dyn Error>> {
30 let contacts = build_contacts();
31 let serialized = serde_json::to_string(&contacts)?;
32 println!("serialized: {}", serialized);
33 let mut f = fs::File::create("/tmp/contacts.json")?;
34 serde_json::to_writer_pretty(&mut f, &contacts)?;
38 fn main() -> Result<(), Box<dyn Error>> {