Skip to content

Instantly share code, notes, and snippets.

@BetterProgramming
Created March 23, 2020 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BetterProgramming/5359b2a8b203361bc2d56024eb075696 to your computer and use it in GitHub Desktop.
Save BetterProgramming/5359b2a8b203361bc2d56024eb075696 to your computer and use it in GitHub Desktop.
use ron::ser;
pub fn save() -> std::io::Result<()> {
let data = Config {
token: private::TOKEN,
prefix: private::PREFIX,
};
let pretty = PrettyConfig::new()
.with_depth_limit(2)
.with_separate_tuple_members(true)
.with_enum_arrays(true);
let s = ser::to_string_pretty(&data, pretty)
.expect("Serialization failed!");
let mut file = std::fs::File::create("config.ron")?;
if let Err(why) = write!(file, "{}", s) {
println!("Failed writing to file: {}", why);
} else {
println!("Write operation succeeded!");
}
return Ok(());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment