Merge pull request #14 from matthiasbeyer/clippy

Fix clippy warnings and add CI check
This commit is contained in:
Scott Boggs 2022-12-28 08:45:46 -05:00 committed by GitHub
commit 8516091c5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 89 additions and 68 deletions

View File

@ -20,3 +20,15 @@ jobs:
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
clippy:
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.65.0
components: clippy
- run: cargo clippy -- -D warnings

View File

@ -110,13 +110,13 @@ impl<'a> AppBuilder<'a> {
Ok(App {
client_name: self
.client_name
.ok_or_else(|| Error::MissingField("client_name"))?
.ok_or(Error::MissingField("client_name"))?
.into(),
redirect_uris: self
.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()),
})
}
@ -126,7 +126,7 @@ impl<'a> TryInto<App> for AppBuilder<'a> {
type Error = Error;
fn try_into(self) -> Result<App> {
Ok(self.build()?)
self.build()
}
}

View File

@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
/// Raw data about mastodon app. Save `Data` using `serde` to prevent needing
/// to authenticate on every run.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize, Default)]
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize, Default)]
pub struct Data {
/// Base url of instance eg. `https://botsin.space`.
pub base: Cow<'static, str>,

View File

@ -56,7 +56,7 @@ pub struct Account {
}
/// A single name: value pair from a user's profile
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
pub struct MetadataField {
/// name part of metadata
pub name: String,
@ -74,7 +74,7 @@ impl MetadataField {
}
/// An extra object given from `verify_credentials` giving defaults about a user
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
pub struct Source {
privacy: Option<status_builder::Visibility>,
#[serde(deserialize_with = "string_or_bool")]
@ -84,7 +84,7 @@ pub struct Source {
}
fn string_or_bool<'de, D: Deserializer<'de>>(val: D) -> ::std::result::Result<bool, D::Error> {
#[derive(Clone, Debug, Deserialize, PartialEq)]
#[derive(Clone, Debug, Deserialize, PartialEq, Eq)]
#[serde(untagged)]
pub enum BoolOrString {
Bool(bool),
@ -108,7 +108,7 @@ fn string_or_bool<'de, D: Deserializer<'de>>(val: D) -> ::std::result::Result<bo
})
}
#[derive(Debug, Default, Clone, Serialize, PartialEq)]
#[derive(Debug, Default, Clone, Serialize, PartialEq, Eq)]
pub(crate) struct UpdateSource {
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) privacy: Option<status_builder::Visibility>,
@ -116,7 +116,7 @@ pub(crate) struct UpdateSource {
pub(crate) sensitive: Option<bool>,
}
#[derive(Debug, Default, Serialize, PartialEq)]
#[derive(Debug, Default, Serialize, PartialEq, Eq)]
pub(crate) struct Credentials {
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) display_name: Option<String>,

View File

@ -48,7 +48,7 @@ pub struct ImageDetails {
}
/// The type of media attachment.
#[derive(Debug, Deserialize, Serialize, Clone, Copy, PartialEq)]
#[derive(Debug, Deserialize, Serialize, Clone, Copy, PartialEq, Eq)]
pub enum MediaType {
/// An image.
#[serde(rename = "image")]

View File

@ -3,7 +3,7 @@
use serde::{Deserialize, Serialize};
/// A card of a status.
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
pub struct Card {
/// The url associated with the card.
pub url: String,

View File

@ -1,7 +1,7 @@
use serde::{Deserialize, Serialize};
/// Represents a single Filter
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Filter {
id: String,
phrase: String,
@ -12,7 +12,7 @@ pub struct Filter {
}
/// Represents the various types of Filter contexts
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum FilterContext {
/// Represents the "home" context
#[serde(rename = "home")]

View File

@ -32,14 +32,14 @@ pub struct Instance {
}
/// Object containing url for streaming api.
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
pub struct StreamingApi {
/// Url for streaming API, typically a `wss://` url.
pub streaming_api: String,
}
/// Statistics about the Mastodon instance.
#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq)]
#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq)]
pub struct Stats {
user_count: u64,
status_count: u64,

View File

@ -90,9 +90,7 @@ impl<'a, T: Clone + for<'de> Deserialize<'de> + Serialize> ItemsIter<T> {
Some((item, this))
} else {
if this.need_next_page() {
if this.fill_next_page().await.is_none() {
return None;
}
this.fill_next_page().await?;
}
let idx = this.cur_idx;
this.cur_idx += 1;

View File

@ -1,7 +1,7 @@
use serde::{Deserialize, Serialize};
/// Used for ser/de of list resources
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
pub struct List {
id: String,
title: String,

View File

@ -1,7 +1,7 @@
use serde::{Deserialize, Serialize};
/// Represents a `mention` used in a status
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct Mention {
/// URL of user's profile (can be remote)
pub url: String,

View File

@ -33,7 +33,7 @@ pub mod search_result;
pub mod status;
/// An empty JSON object.
#[derive(Deserialize, Serialize, Debug, Copy, Clone, PartialEq)]
#[derive(Deserialize, Serialize, Debug, Copy, Clone, PartialEq, Eq)]
pub struct Empty {}
/// The purpose of this module is to alleviate imports of many common

View File

@ -5,6 +5,7 @@ use chrono::prelude::*;
use serde::{Deserialize, Serialize};
/// A struct containing info about a notification.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
pub struct Notification {
/// The notification ID.
@ -21,7 +22,7 @@ pub struct Notification {
}
/// The type of notification.
#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq)]
#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum NotificationType {
/// Someone mentioned the application client in another status.

View File

@ -1,7 +1,7 @@
use serde::{Deserialize, Serialize};
/// Represents the `alerts` key of the `Subscription` object
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Default)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
pub struct Alerts {
/// flag for follow alerts
pub follow: Option<bool>,
@ -14,7 +14,7 @@ pub struct Alerts {
}
/// Represents a new Push subscription
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Subscription {
/// The `id` of the subscription
pub id: String,
@ -37,19 +37,19 @@ pub(crate) mod add_subscription {
pub(crate) data: Option<Data>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Default)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Default)]
pub(crate) struct Subscription {
pub(crate) endpoint: String,
pub(crate) keys: Keys,
}
#[derive(Debug, Clone, PartialEq, Serialize, Default)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Default)]
pub(crate) struct Keys {
pub(crate) p256dh: String,
pub(crate) auth: String,
}
#[derive(Debug, Clone, PartialEq, Serialize, Default)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Default)]
pub(crate) struct Data {
pub(crate) alerts: Option<Alerts>,
}
@ -60,12 +60,12 @@ pub(crate) mod update_data {
use super::Alerts;
#[derive(Debug, Clone, PartialEq, Serialize, Default)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Default)]
pub(crate) struct Data {
pub(crate) alerts: Option<Alerts>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Default)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Default)]
pub(crate) struct Form {
pub(crate) id: String,
pub(crate) data: Data,

View File

@ -4,7 +4,7 @@
use serde::{Deserialize, Serialize};
/// A struct containing information about a relationship with another account.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct Relationship {
/// Target account id
pub id: String,

View File

@ -3,7 +3,7 @@
use serde::{Deserialize, Serialize};
/// A struct containing info about a report.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct Report {
/// The ID of the report.
pub id: String,

View File

@ -65,7 +65,7 @@ pub struct Status {
}
/// A mention of another user.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct Mention {
/// URL of user's profile (can be remote).
pub url: String,
@ -78,7 +78,7 @@ pub struct Mention {
}
/// Struct representing an emoji within text.
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct Emoji {
/// The shortcode of the emoji
pub shortcode: String,
@ -93,6 +93,7 @@ pub struct Emoji {
/// as a [`Tag`](https://docs.joinmastodon.org/entities/Tag/). In the case of
/// the former, at the time of writing, the history field is always empty and
/// the following field is always none.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct Tag {
/// The hashtag, not including the preceding `#`.
@ -107,7 +108,7 @@ pub struct Tag {
}
/// Application details.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct Application {
/// Name of the application.
pub name: String,
@ -116,7 +117,7 @@ pub struct Application {
}
/// Usage statistics for given days (typically the past week).
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct TagHistory {
/// UNIX timestamp on midnight of the given day.
pub day: String,

View File

@ -173,7 +173,7 @@ from! {
macro_rules! format_err {
( $( $arg:tt )* ) => {
{
crate::Error::Other(format!($($arg)*))
$crate::Error::Other(format!($($arg)*))
}
}
}

View File

@ -30,7 +30,7 @@ pub fn event_stream(
while let Some(line) = lines_iter.next_line().await? {
debug!(message = line, location = &location; "received 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);

View File

@ -86,6 +86,7 @@ macro_rules! paged_routes {
_marker: ::std::marker::PhantomData<&'a ()>,
}
#[allow(clippy::redundant_field_names)]
let qs_data = Data {
$(
$param: $param,
@ -135,6 +136,7 @@ macro_rules! route_v2 {
_marker: ::std::marker::PhantomData<&'a ()>,
}
#[allow(clippy::redundant_field_names)]
let qs_data = Data {
$(
$param: $param,
@ -349,6 +351,7 @@ macro_rules! route {
_marker: ::std::marker::PhantomData<&'a ()>,
}
#[allow(clippy::redundant_field_names)]
let qs_data = Data {
$(
$param: $param,

View File

@ -326,11 +326,11 @@ impl Mastodon {
if ids.len() == 1 {
url += "id=";
url += &ids[0];
url += ids[0];
} else {
for id in ids {
url += "id[]=";
url += &id;
url += id;
url += "&";
}
url.pop();
@ -427,7 +427,7 @@ impl Mastodon {
},
Err(err) => {
error!(path = as_debug!(path), error = as_debug!(err); "error reading file contents for multipart form");
return Err(err.into());
Err(err.into())
},
}
}

View File

@ -179,7 +179,7 @@ fn get_links(response: &Response, call_id: Uuid) -> Result<(Option<Url>, Option<
let link_header = link_header.to_str()?;
trace!(link_header = link_header, call_id = as_debug!(call_id); "parsing link header");
let link_header = link_header.as_bytes();
let link_header: Link = parsing::from_raw_str(&link_header)?;
let link_header: Link = parsing::from_raw_str(link_header)?;
for value in link_header.values() {
if let Some(relations) = value.rel() {
if relations.contains(&RelationType::Next) {

View File

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

View File

@ -9,7 +9,7 @@ use std::time::Duration;
/// use mastodon_async::{entities::filter::FilterContext, requests::AddFilterRequest};
/// let request = AddFilterRequest::new("foo", FilterContext::Home);
/// ```
#[derive(Debug, Clone, PartialEq, Serialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct AddFilterRequest {
phrase: String,
context: FilterContext,

View File

@ -12,7 +12,7 @@ use crate::{
///
/// let keys = Keys::new("anetohias===", "oeatssah=");
/// ```
#[derive(Debug, Default, Clone, PartialEq)]
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct Keys {
pub(crate) p256dh: String,
pub(crate) auth: String,
@ -55,7 +55,7 @@ impl Keys {
/// client.add_push_subscription(&request).await.unwrap();
/// });
/// ```
#[derive(Debug, Default, Clone, PartialEq)]
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct AddPushRequest {
endpoint: String,
@ -215,7 +215,7 @@ impl AddPushRequest {
/// client.update_push_data(&request).await.unwrap();
/// });
/// ```
#[derive(Debug, Default, Clone, PartialEq, Serialize)]
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize)]
pub struct UpdatePushRequest {
id: String,
follow: Option<bool>,

View File

@ -29,7 +29,7 @@ mod bool_qs_serialize {
/// request.only_media().pinned().since_id("foo");
/// assert_eq!(&request.to_querystring().expect("Couldn't serialize qs")[..], "?only_media=1&pinned=1&since_id=foo");
/// ```
#[derive(Clone, Debug, Default, PartialEq, Serialize)]
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize)]
pub struct StatusesRequest<'a> {
#[serde(skip_serializing_if = "bool_qs_serialize::is_false")]
#[serde(serialize_with = "bool_qs_serialize::serialize")]
@ -50,16 +50,16 @@ pub struct StatusesRequest<'a> {
min_id: Option<Cow<'a, str>>,
}
impl<'a> Into<Option<StatusesRequest<'a>>> for &'a mut StatusesRequest<'a> {
fn into(self) -> Option<StatusesRequest<'a>> {
impl<'a> From<&'a mut StatusesRequest<'a>> for Option<StatusesRequest<'a>> {
fn from(sr: &'a mut StatusesRequest<'a>) -> Self {
Some(StatusesRequest {
only_media: self.only_media,
exclude_replies: self.exclude_replies,
pinned: self.pinned,
max_id: self.max_id.clone(),
since_id: self.since_id.clone(),
limit: self.limit.clone(),
min_id: self.min_id.clone(),
only_media: sr.only_media,
exclude_replies: sr.exclude_replies,
pinned: sr.pinned,
max_id: sr.max_id.clone(),
since_id: sr.since_id.clone(),
limit: sr.limit,
min_id: sr.min_id.clone(),
})
}
}

View File

@ -26,7 +26,7 @@ use crate::{
/// let result = client.update_credentials(&mut builder).await.unwrap();
/// });
/// ```
#[derive(Debug, Default, Clone, PartialEq)]
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct UpdateCredsRequest {
display_name: Option<String>,
note: Option<String>,
@ -176,8 +176,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(),
})

View File

@ -38,7 +38,7 @@ impl FromStr for Scopes {
fn from_str(s: &str) -> Result<Scopes, Self::Err> {
let mut set = HashSet::new();
for scope in s.split_whitespace() {
let scope = Scope::from_str(&scope)?;
let scope = Scope::from_str(scope)?;
set.insert(scope);
}
Ok(Scopes {
@ -184,7 +184,7 @@ impl Scopes {
.scopes
.union(&other.scopes)
.into_iter()
.map(|s| *s)
.copied()
.collect();
Scopes {
scopes: newset,
@ -264,7 +264,7 @@ impl fmt::Display for Scopes {
/// Permission scope of the application.
/// [Details on what each permission provides][1]
/// [1]: https://github.com/tootsuite/documentation/blob/master/Using-the-API/OAuth-details.md)
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Hash, Serialize)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize)]
enum Scope {
/// Read only permissions.
#[serde(rename = "read")]
@ -302,6 +302,12 @@ impl FromStr for Scope {
}
}
impl PartialOrd for Scope {
fn partial_cmp(&self, other: &Scope) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Ord for Scope {
fn cmp(&self, other: &Scope) -> Ordering {
match (*self, *other) {

View File

@ -17,7 +17,7 @@ use serde::{Deserialize, Serialize};
/// .language(Language::Eng)
/// .build().unwrap();
/// ```
#[derive(Debug, Default, Clone, PartialEq)]
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct StatusBuilder {
status: Option<String>,
in_reply_to_id: Option<String>,
@ -210,17 +210,17 @@ 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(),
})
}
}
/// Represents a post that can be sent to the POST /api/v1/status endpoint
#[derive(Debug, Default, Clone, Serialize, PartialEq)]
#[derive(Debug, Default, Clone, Serialize, PartialEq, Eq)]
pub struct NewStatus {
#[serde(skip_serializing_if = "Option::is_none")]
status: Option<String>,
@ -241,7 +241,7 @@ pub struct NewStatus {
}
/// The visibility of a status.
#[derive(Clone, Copy, Debug, Deserialize, Serialize, PartialEq)]
#[derive(Clone, Copy, Debug, Deserialize, Serialize, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum Visibility {
/// A Direct message to a user