diff --git a/src/helpers/json.rs b/src/helpers/json.rs index 73e59cb..e12e602 100644 --- a/src/helpers/json.rs +++ b/src/helpers/json.rs @@ -6,8 +6,7 @@ use std::{ use serde_json; -use crate::Result; -use data::Data; +use crate::{Data, Result}; /// Attempts to deserialize a Data struct from a string pub fn from_str(s: &str) -> Result { diff --git a/src/helpers/log.rs b/src/helpers/log.rs index f398b3f..147e98c 100644 --- a/src/helpers/log.rs +++ b/src/helpers/log.rs @@ -1,4 +1,4 @@ -use serde::Serialize; +use serde::{Deserialize, Serialize}; /// Log metadata about this request based on the type given: /// diff --git a/src/helpers/toml.rs b/src/helpers/toml.rs index 55edddb..086bbe2 100644 --- a/src/helpers/toml.rs +++ b/src/helpers/toml.rs @@ -6,8 +6,7 @@ use std::{ use tomlcrate; -use crate::Result; -use data::Data; +use crate::{Data, Result}; /// Attempts to deserialize a Data struct from a string pub fn from_str(s: &str) -> Result { @@ -61,8 +60,7 @@ pub fn to_writer(data: &Data, writer: W) -> Result<()> { pub fn to_file>(data: &Data, path: P) -> Result<()> { let mut options = OpenOptions::new(); options.create(true).write(true).truncate(true); - to_file_with_options(data, path, options)?; - Ok(()) + to_file_with_options(data, path, options) } /// Attempts to serialize a Data struct to a file diff --git a/src/lib.rs b/src/lib.rs index 790e06a..b778e96 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -65,23 +65,12 @@ unused_qualifications )] -// #[macro_use] -extern crate log; #[macro_use] extern crate doc_comment; -extern crate hyper_old_types; -extern crate isolang; #[macro_use] extern crate serde_json; -extern crate chrono; -extern crate reqwest; #[macro_use] extern crate serde; -extern crate serde_qs; -extern crate serde_urlencoded; -extern crate tap_reader; -extern crate tungstenite; -extern crate url; #[cfg(feature = "env")] extern crate envy; @@ -111,7 +100,7 @@ pub use requests::{ UpdateCredsRequest, UpdatePushRequest, }; -pub use status_builder::{NewStatus, StatusBuilder}; +pub use status_builder::{NewStatus, StatusBuilder, Visibility}; /// Registering your App pub mod apps; @@ -141,6 +130,7 @@ mod macros; pub mod prelude { pub use crate::{ scopes::Scopes, + status_builder::Visibility, Data, Mastodon, // MastodonClient, diff --git a/src/status_builder.rs b/src/status_builder.rs index e0a1db2..20c02e9 100644 --- a/src/status_builder.rs +++ b/src/status_builder.rs @@ -1,3 +1,5 @@ +use std::str::FromStr; + use isolang::Language; use serde::{Deserialize, Serialize}; @@ -258,6 +260,20 @@ impl Default for Visibility { } } +impl FromStr for Visibility { + type Err = crate::Error; + + fn from_str(s: &str) -> Result { + match s.to_ascii_lowercase().as_str() { + "direct" => Ok(Visibility::Direct), + "private" => Ok(Visibility::Private), + "unlisted" => Ok(Visibility::Unlisted), + "public" => Ok(Visibility::Public), + invalid => Err(format!("unrecognized visibility '{invalid}'").into()), + } + } +} + #[cfg(test)] mod tests { use super::*;