misc fixups
This commit is contained in:
parent
6afdc06cc7
commit
c811f42054
|
@ -6,8 +6,7 @@ use std::{
|
||||||
|
|
||||||
use serde_json;
|
use serde_json;
|
||||||
|
|
||||||
use crate::Result;
|
use crate::{Data, Result};
|
||||||
use data::Data;
|
|
||||||
|
|
||||||
/// Attempts to deserialize a Data struct from a string
|
/// Attempts to deserialize a Data struct from a string
|
||||||
pub fn from_str(s: &str) -> Result<Data> {
|
pub fn from_str(s: &str) -> Result<Data> {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use serde::Serialize;
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
/// Log metadata about this request based on the type given:
|
/// Log metadata about this request based on the type given:
|
||||||
///
|
///
|
||||||
|
|
|
@ -6,8 +6,7 @@ use std::{
|
||||||
|
|
||||||
use tomlcrate;
|
use tomlcrate;
|
||||||
|
|
||||||
use crate::Result;
|
use crate::{Data, Result};
|
||||||
use data::Data;
|
|
||||||
|
|
||||||
/// Attempts to deserialize a Data struct from a string
|
/// Attempts to deserialize a Data struct from a string
|
||||||
pub fn from_str(s: &str) -> Result<Data> {
|
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<()> {
|
pub fn to_file<P: AsRef<Path>>(data: &Data, path: P) -> Result<()> {
|
||||||
let mut options = OpenOptions::new();
|
let mut options = OpenOptions::new();
|
||||||
options.create(true).write(true).truncate(true);
|
options.create(true).write(true).truncate(true);
|
||||||
to_file_with_options(data, path, options)?;
|
to_file_with_options(data, path, options)
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Attempts to serialize a Data struct to a file
|
/// Attempts to serialize a Data struct to a file
|
||||||
|
|
14
src/lib.rs
14
src/lib.rs
|
@ -65,23 +65,12 @@
|
||||||
unused_qualifications
|
unused_qualifications
|
||||||
)]
|
)]
|
||||||
|
|
||||||
// #[macro_use]
|
|
||||||
extern crate log;
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate doc_comment;
|
extern crate doc_comment;
|
||||||
extern crate hyper_old_types;
|
|
||||||
extern crate isolang;
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
extern crate chrono;
|
|
||||||
extern crate reqwest;
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
extern crate serde_qs;
|
|
||||||
extern crate serde_urlencoded;
|
|
||||||
extern crate tap_reader;
|
|
||||||
extern crate tungstenite;
|
|
||||||
extern crate url;
|
|
||||||
|
|
||||||
#[cfg(feature = "env")]
|
#[cfg(feature = "env")]
|
||||||
extern crate envy;
|
extern crate envy;
|
||||||
|
@ -111,7 +100,7 @@ pub use requests::{
|
||||||
UpdateCredsRequest,
|
UpdateCredsRequest,
|
||||||
UpdatePushRequest,
|
UpdatePushRequest,
|
||||||
};
|
};
|
||||||
pub use status_builder::{NewStatus, StatusBuilder};
|
pub use status_builder::{NewStatus, StatusBuilder, Visibility};
|
||||||
|
|
||||||
/// Registering your App
|
/// Registering your App
|
||||||
pub mod apps;
|
pub mod apps;
|
||||||
|
@ -141,6 +130,7 @@ mod macros;
|
||||||
pub mod prelude {
|
pub mod prelude {
|
||||||
pub use crate::{
|
pub use crate::{
|
||||||
scopes::Scopes,
|
scopes::Scopes,
|
||||||
|
status_builder::Visibility,
|
||||||
Data,
|
Data,
|
||||||
Mastodon,
|
Mastodon,
|
||||||
// MastodonClient,
|
// MastodonClient,
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
use isolang::Language;
|
use isolang::Language;
|
||||||
use serde::{Deserialize, Serialize};
|
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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
Loading…
Reference in New Issue