Skip to content

Instantly share code, notes, and snippets.

@pimeys
Created July 18, 2018 08:47
Show Gist options
  • Save pimeys/ed98f2eda3234797b20d5b7c43265df5 to your computer and use it in GitHub Desktop.
Save pimeys/ed98f2eda3234797b20d5b7c43265df5 to your computer and use it in GitHub Desktop.
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
use std::fs::File;
use std::io::Write;
#[derive(Serialize)]
struct Foo {
bar: &'static str,
}
fn main() {
let foo = Foo { bar: "lol" };
let mut file = File::create("foo.json").unwrap();
file.write_all(&serde_json::to_vec(&foo).unwrap()).unwrap();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment