diff options
author | Paul Woolcock <paul@woolcock.us> | 2018-08-23 14:11:44 -0400 |
---|---|---|
committer | Paul Woolcock <paul@woolcock.us> | 2018-08-23 14:47:46 -0400 |
commit | 6ddea8776578c36dd4c83a5f156ef54fb8e35113 (patch) | |
tree | 1e778beecc201c6025eb91a75b190b7e614006a3 /examples | |
parent | 384d3d2c41e8bb7c1d2a74bc94d4491a509f154d (diff) |
Use the new toml helpers instead of the toml crate
Diffstat (limited to 'examples')
-rw-r--r-- | examples/register.rs | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/examples/register.rs b/examples/register.rs index c5479d8..7437dc9 100644 --- a/examples/register.rs +++ b/examples/register.rs @@ -1,14 +1,14 @@ extern crate elefren; -extern crate toml; pub use self::elefren::{Data, MastodonClient}; -use std::{error::Error, fs, io}; +use std::{error::Error, io}; use self::elefren::{ apps::{App, Scopes}, Mastodon, Registration, + data::toml, }; #[allow(dead_code)] @@ -19,8 +19,7 @@ fn main() -> Result<(), Box<Error>> { #[allow(dead_code)] pub fn get_mastodon_data() -> Result<Mastodon, Box<Error>> { - if let Ok(config) = fs::read_to_string("mastodon-data.toml") { - let data: Data = toml::from_str(&config)?; + if let Ok(data) = toml::from_file("mastodon-data.toml") { Ok(Mastodon::from(data)) } else { register() @@ -39,14 +38,12 @@ pub fn register() -> Result<Mastodon, Box<Error>> { let url = registered.authorize_url()?; println!("Click this link to authorize on Mastodon: {}", url); - let input = read_line("Paste the returned authorization code: ")?; + let code = read_line("Paste the returned authorization code: ")?; - let code = input.trim(); - let mastodon = registered.complete(code.to_string())?; + let mastodon = registered.complete(code)?; // Save app data for using on the next run. - let toml = toml::to_string(&*mastodon)?; - fs::write("mastodon-data.toml", toml.as_bytes())?; + toml::to_file(&*mastodon, "mastodon-data.toml")?; Ok(mastodon) } @@ -57,5 +54,5 @@ pub fn read_line(message: &str) -> Result<String, Box<Error>> { let mut input = String::new(); io::stdin().read_line(&mut input)?; - Ok(input) + Ok(input.trim().to_string()) } |