diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 1bf54bc..621067a 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -38,7 +38,7 @@ jobs: - uses: actions-rs/cargo@v1 with: command: fmt - args: --features all --all -- --check + args: --verbose --all -- --check - uses: actions-rs/cargo@v1 with: command: clippy diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 8d8f57e..0000000 --- a/.travis.yml +++ /dev/null @@ -1,42 +0,0 @@ -sudo: required -language: rust -dist: trusty -addons: - apt: - packages: - - libssl-dev -cache: - directories: - - $HOME/.cargo -env: - - ELEFREN_FEATURES="--features toml" - - ELEFREN_FEATURES="--features json" - - ELEFREN_FEATURES="--features all" - - ELEFREN_FEATURES="" -os: - - linux - - osx -rust: - - stable - - beta - - nightly -script: - - cargo test $ELEFREN_FEATURES -matrix: - include: - - name: "Coverage" - rust: nightly - before_cache: RUSTFLAGS="--cfg procmacro2_semver_exempt" cargo install -f cargo-tarpaulin - script: cargo build --features all - after_success: cargo tarpaulin --ciserver travis-ci --coveralls $TRAVIS_JOB_ID --features all - - - name: "rustfmt" - rust: nightly - before_script: rustup component add rustfmt-preview - script: cargo fmt --all -- --check - - allow_failures: - - rust: nightly -notifications: - email: - on_success: never diff --git a/Cargo.toml b/Cargo.toml index 63fdef9..e4ee5a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,6 @@ keywords = ["api", "web", "social", "mastodon", "wrapper"] categories = ["web-programming", "web-programming::http-client", "api-bindings"] edition = "2018" - [dependencies] doc-comment = "0.3" envy = { version = "0.4.0", optional = true } @@ -38,9 +37,9 @@ json = [] env = ["envy"] all = ["toml", "json", "env"] rustls-tls = ["reqwest/rustls-tls"] +nightly = [] [dev-dependencies] -skeptic = "0.13.3" tempfile = "3.0.3" indoc = "1.0.2" pretty_env_logger = "0.4.0" diff --git a/src/apps.rs b/src/apps.rs index e3ce035..94f503e 100644 --- a/src/apps.rs +++ b/src/apps.rs @@ -126,7 +126,7 @@ impl<'a> AppBuilder<'a> { .redirect_uris .unwrap_or_else(|| "urn:ietf:wg:oauth:2.0:oob".into()) .into(), - scopes: self.scopes.unwrap_or_else(|| Scopes::read_all()), + scopes: self.scopes.unwrap_or_else(Scopes::read_all), website: self.website.map(|s| s.into()), }) } diff --git a/src/entities/account.rs b/src/entities/account.rs index b66a37a..a0b1fd5 100644 --- a/src/entities/account.rs +++ b/src/entities/account.rs @@ -135,7 +135,7 @@ pub(crate) struct Credentials { mod fields_attributes_ser { use super::*; use serde::ser::{SerializeMap, Serializer}; - pub(crate) fn ser(attrs: &Vec, serializer: S) -> Result + pub(crate) fn ser(attrs: &[MetadataField], serializer: S) -> Result where S: Serializer, { diff --git a/src/entities/event.rs b/src/entities/event.rs index 9311f6a..bbf5af1 100644 --- a/src/entities/event.rs +++ b/src/entities/event.rs @@ -1,6 +1,7 @@ use crate::entities::{notification::Notification, status::Status}; #[derive(Debug, Clone)] +#[allow(clippy::large_enum_variant)] /// Events that come from the /streaming/user API call pub enum Event { /// Update event diff --git a/src/entities/itemsiter.rs b/src/entities/itemsiter.rs index 796a3c3..dbf3e36 100644 --- a/src/entities/itemsiter.rs +++ b/src/entities/itemsiter.rs @@ -81,10 +81,8 @@ impl<'a, T: Clone + for<'de> Deserialize<'de>, H: HttpSend> Iterator for ItemsIt } Some(self.page.initial_items[idx].clone()) } else { - if self.need_next_page() { - if self.fill_next_page().is_none() { - return None; - } + if self.need_next_page() && self.fill_next_page().is_none() { + return None; } let idx = self.cur_idx; self.cur_idx += 1; diff --git a/src/helpers/env.rs b/src/helpers/env.rs index 7bac385..56cf4c2 100644 --- a/src/helpers/env.rs +++ b/src/helpers/env.rs @@ -1,5 +1,3 @@ -use envy; - use crate::{data::Data, Result}; /// Attempts to deserialize a Data struct from the environment diff --git a/src/helpers/json.rs b/src/helpers/json.rs index 70871f2..65305d0 100644 --- a/src/helpers/json.rs +++ b/src/helpers/json.rs @@ -4,8 +4,6 @@ use std::{ path::Path, }; -use serde_json; - use crate::{data::Data, Result}; /// Attempts to deserialize a Data struct from a string @@ -48,7 +46,7 @@ pub fn to_vec(data: &Data) -> Result> { pub fn to_writer(data: &Data, writer: W) -> Result<()> { let mut buf_writer = BufWriter::new(writer); let vec = to_vec(data)?; - buf_writer.write(&vec)?; + buf_writer.write_all(&vec)?; Ok(()) } diff --git a/src/helpers/toml.rs b/src/helpers/toml.rs index 5b562bf..6a63787 100644 --- a/src/helpers/toml.rs +++ b/src/helpers/toml.rs @@ -46,7 +46,7 @@ pub fn to_vec(data: &Data) -> Result> { pub fn to_writer(data: &Data, writer: W) -> Result<()> { let mut buf_writer = BufWriter::new(writer); let vec = to_vec(data)?; - buf_writer.write(&vec)?; + buf_writer.write_all(&vec)?; Ok(()) } diff --git a/src/lib.rs b/src/lib.rs index 3b08ae0..7c5925a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -69,7 +69,7 @@ unused_import_braces, unused_qualifications )] -#![allow(broken_intra_doc_links)] +#![cfg_attr(feature = "nightly", allow(broken_intra_doc_links))] use std::{borrow::Cow, io::BufRead, ops}; @@ -254,9 +254,9 @@ impl MastodonClient for Mastodon { let status = response.status(); if status.is_client_error() { - return Err(Error::Client(status.clone())); + return Err(Error::Client(status)); } else if status.is_server_error() { - return Err(Error::Server(status.clone())); + return Err(Error::Server(status)); } deserialise(response) @@ -270,9 +270,9 @@ impl MastodonClient for Mastodon { let status = response.status(); if status.is_client_error() { - return Err(Error::Client(status.clone())); + return Err(Error::Client(status)); } else if status.is_server_error() { - return Err(Error::Server(status.clone())); + return Err(Error::Server(status)); } deserialise(response) @@ -286,9 +286,9 @@ impl MastodonClient for Mastodon { let status = response.status(); if status.is_client_error() { - return Err(Error::Client(status.clone())); + return Err(Error::Client(status)); } else if status.is_server_error() { - return Err(Error::Server(status.clone())); + return Err(Error::Server(status)); } deserialise(response) @@ -627,7 +627,7 @@ impl MastodonClient for Mastodon { .multipart(form_data), )?; - let status = response.status().clone(); + let status = response.status(); if status.is_client_error() { return Err(Error::Client(status)); @@ -675,7 +675,7 @@ impl Iterator for EventReader { loop { if let Ok(line) = self.0.read_message() { let line = line.trim().to_string(); - if line.starts_with(":") || line.is_empty() { + if line.starts_with(':') || line.is_empty() { continue; } lines.push(line); @@ -773,7 +773,7 @@ impl MastodonBuilder { pub fn build(self) -> Result> { Ok(if let Some(data) = self.data { Mastodon { - client: self.client.unwrap_or_else(|| Client::new()), + client: self.client.unwrap_or_else(Client::new), http_sender: self.http_sender, data, } diff --git a/src/macros.rs b/src/macros.rs index c6d031d..59ee854 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -79,7 +79,7 @@ macro_rules! paged_routes { let qs_data = Data { $( - $param: $param, + $param, )* _marker: ::std::marker::PhantomData, }; @@ -125,7 +125,7 @@ macro_rules! route_v2 { let qs_data = Data { $( - $param: $param, + $param, )* _marker: ::std::marker::PhantomData, }; @@ -168,7 +168,7 @@ macro_rules! route { let qs_data = Data { $( - $param: $param, + $param, )* _marker: ::std::marker::PhantomData, }; diff --git a/src/page.rs b/src/page.rs index 67fb340..613a326 100644 --- a/src/page.rs +++ b/src/page.rs @@ -59,7 +59,7 @@ macro_rules! pages { /// page: RefCell>>, /// } /// let client = Mastodon::from(data); -/// let home = client.get_home_timeline()?.to_owned(); +/// let home = client.get_home_timeline()?.into_owned(); /// let tl = HomeTimeline { /// client, /// page: RefCell::new(Some(home)), @@ -148,7 +148,7 @@ impl<'a, T: Clone + for<'de> Deserialize<'de>, H: HttpSend> Page<'a, T, H> { /// page: RefCell>>, /// } /// let client = Mastodon::from(data); - /// let home = client.get_home_timeline()?.to_owned(); + /// let home = client.get_home_timeline()?.into_owned(); /// let tl = HomeTimeline { /// client, /// page: RefCell::new(Some(home)), @@ -156,7 +156,7 @@ impl<'a, T: Clone + for<'de> Deserialize<'de>, H: HttpSend> Page<'a, T, H> { /// # Ok(()) /// # } /// ``` - pub fn to_owned(self) -> OwnedPage { + pub fn into_owned(self) -> OwnedPage { OwnedPage::from(self) } diff --git a/src/registration.rs b/src/registration.rs index 0adb1cd..1ac5e7f 100644 --- a/src/registration.rs +++ b/src/registration.rs @@ -16,7 +16,7 @@ use crate::{ Result, }; -const DEFAULT_REDIRECT_URI: &'static str = "urn:ietf:wg:oauth:2.0:oob"; +const DEFAULT_REDIRECT_URI: &str = "urn:ietf:wg:oauth:2.0:oob"; /// Handles registering your mastodon app to your instance. It is recommended /// you cache your data struct to avoid registering on every run. diff --git a/src/requests/statuses.rs b/src/requests/statuses.rs index d9474fa..5dd16c5 100644 --- a/src/requests/statuses.rs +++ b/src/requests/statuses.rs @@ -1,6 +1,5 @@ use crate::errors::Error; use serde::Serialize; -use serde_qs; use std::{borrow::Cow, convert::Into}; mod bool_qs_serialize { @@ -59,7 +58,7 @@ impl<'a> Into>> for &'a mut StatusesRequest<'a> { pinned: self.pinned, max_id: self.max_id.clone(), since_id: self.since_id.clone(), - limit: self.limit.clone(), + limit: self.limit, min_id: self.min_id.clone(), }) } diff --git a/src/requests/update_credentials.rs b/src/requests/update_credentials.rs index f3e7c7e..a7a4693 100644 --- a/src/requests/update_credentials.rs +++ b/src/requests/update_credentials.rs @@ -193,8 +193,8 @@ impl UpdateCredsRequest { avatar: self.avatar.clone(), header: self.avatar.clone(), source: Some(UpdateSource { - privacy: self.privacy.clone(), - sensitive: self.sensitive.clone(), + privacy: self.privacy, + sensitive: self.sensitive, }), fields_attributes: self.field_attributes.clone(), }) diff --git a/src/scopes.rs b/src/scopes.rs index 0a7a0a6..f8ff719 100644 --- a/src/scopes.rs +++ b/src/scopes.rs @@ -217,8 +217,7 @@ impl Scopes { let newset: HashSet<_> = self .scopes .union(&other.scopes) - .into_iter() - .map(|s| *s) + .copied() .collect(); Scopes { scopes: newset, diff --git a/src/status_builder.rs b/src/status_builder.rs index 1e62489..6ddd9e9 100644 --- a/src/status_builder.rs +++ b/src/status_builder.rs @@ -242,10 +242,10 @@ impl StatusBuilder { status: self.status.clone(), in_reply_to_id: self.in_reply_to_id.clone(), media_ids: self.media_ids.clone(), - sensitive: self.sensitive.clone(), + sensitive: self.sensitive, spoiler_text: self.spoiler_text.clone(), - visibility: self.visibility.clone(), - language: self.language.clone(), + visibility: self.visibility, + language: self.language, content_type: self.content_type.clone(), }) }