misc fixups

This commit is contained in:
D. Scott Boggs 2022-12-18 16:06:30 -05:00
parent 6afdc06cc7
commit c811f42054
5 changed files with 22 additions and 19 deletions

View File

@ -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<Data> {

View File

@ -1,4 +1,4 @@
use serde::Serialize;
use serde::{Deserialize, Serialize};
/// Log metadata about this request based on the type given:
///

View File

@ -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<Data> {
@ -61,8 +60,7 @@ pub fn to_writer<W: Write>(data: &Data, writer: W) -> Result<()> {
pub fn to_file<P: AsRef<Path>>(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

View File

@ -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,

View File

@ -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<Self, Self::Err> {
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::*;