From 9034b07ae0e7efdc247060c2bec8f02c021de41c Mon Sep 17 00:00:00 2001 From: "D. Scott Boggs" Date: Fri, 20 Oct 2023 15:37:09 -0400 Subject: [PATCH 1/3] Update notification dismissal route --- src/mastodon.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mastodon.rs b/src/mastodon.rs index 1d512a8f..ce011268 100644 --- a/src/mastodon.rs +++ b/src/mastodon.rs @@ -87,7 +87,6 @@ impl Mastodon { (get (local: bool,)) get_public_timeline: "timelines/public" => Vec, (post (uri: Cow<'static, str>,)) follows: "follows" => Account, (post) clear_notifications: "notifications/clear" => Empty, - (post (id: &str,)) dismiss_notification: "notifications/dismiss" => Empty, (get) get_push_subscription: "push/subscription" => Subscription, (delete) delete_push_subscription: "push/subscription" => Empty, (get) get_filters: "filters" => Vec, @@ -109,6 +108,7 @@ impl Mastodon { (get) mute[AccountId]: "accounts/{}/mute" => Relationship, (get) unmute[AccountId]: "accounts/{}/unmute" => Relationship, (get) get_notification[NotificationId]: "notifications/{}" => Notification, + (post) dismiss_notification[NotificationId]: "notifications/{}/dismiss" => Empty, (get) get_status[StatusId]: "statuses/{}" => Status, (get) get_context[StatusId]: "statuses/{}/context" => Context, (get) get_card[StatusId]: "statuses/{}/card" => Card, From b9ba308442c3767a74de6eedb088cd8221a37103 Mon Sep 17 00:00:00 2001 From: "D. Scott Boggs" Date: Fri, 20 Oct 2023 15:40:29 -0400 Subject: [PATCH 2/3] clippy fixes --- entities/src/visibility.rs | 9 ++------- examples/log_events.rs | 5 +---- src/errors.rs | 2 +- src/event_stream.rs | 2 +- src/helpers/cli.rs | 2 +- src/helpers/env.rs | 2 +- src/helpers/json.rs | 4 ++-- src/helpers/toml.rs | 4 ++-- src/mastodon.rs | 6 +++--- src/scopes.rs | 19 +++++++------------ 10 files changed, 21 insertions(+), 34 deletions(-) diff --git a/entities/src/visibility.rs b/entities/src/visibility.rs index d5e14c64..43d0afe7 100644 --- a/entities/src/visibility.rs +++ b/entities/src/visibility.rs @@ -3,7 +3,7 @@ use serde::Deserialize; use serde::Serialize; /// The visibility of a status. -#[derive(Clone, Copy, Debug, Deserialize, Serialize, PartialEq, Eq, is_enum_variant)] +#[derive(Clone, Copy, Debug, Default, Deserialize, Serialize, PartialEq, Eq, is_enum_variant)] #[serde(rename_all = "lowercase")] pub enum Visibility { /// A Direct message to a user @@ -13,15 +13,10 @@ pub enum Visibility { /// Not shown in public timelines Unlisted, /// Posted to public timelines + #[default] Public, } -impl Default for Visibility { - fn default() -> Self { - Visibility::Public - } -} - impl std::str::FromStr for Visibility { type Err = crate::error::Error; diff --git a/examples/log_events.rs b/examples/log_events.rs index 8858f4d4..cfac8d2e 100644 --- a/examples/log_events.rs +++ b/examples/log_events.rs @@ -16,10 +16,7 @@ async fn run() -> Result<()> { info!("watching mastodon for events. This will run forever, press Ctrl+C to kill the program."); stream .try_for_each(|(event, _client)| async move { - match event { - // fill in how you want to handle events here. - _ => warn!(event = as_serde!(event); "unrecognized event received"), - } + warn!(event = as_serde!(event); "unrecognized event received"); Ok(()) }) .await?; diff --git a/src/errors.rs b/src/errors.rs index 7d4b7070..0c16d551 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -119,7 +119,7 @@ pub struct ApiError { impl fmt::Display for ApiError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{:?}", self) + write!(f, "{self:?}") } } diff --git a/src/event_stream.rs b/src/event_stream.rs index d6cb7c0c..42d762fb 100644 --- a/src/event_stream.rs +++ b/src/event_stream.rs @@ -83,6 +83,6 @@ pub(crate) fn make_event(lines: &[String]) -> Result { Event::Delete(data) } "filters_changed" => Event::FiltersChanged, - _ => return Err(Error::Other(format!("Unknown event `{}`", event))), + _ => return Err(Error::Other(format!("Unknown event `{event}`"))), }) } diff --git a/src/helpers/cli.rs b/src/helpers/cli.rs index b48d88f9..fdd1583b 100644 --- a/src/helpers/cli.rs +++ b/src/helpers/cli.rs @@ -14,7 +14,7 @@ pub async fn authenticate(registration: Registered) -> Result { let mut stdout = stdout.lock(); let mut stdin = stdin.lock(); - writeln!(&mut stdout, "Click this link to authorize: {}", url)?; + writeln!(&mut stdout, "Click this link to authorize: {url}")?; write!(&mut stdout, "Paste the returned authorization code: ")?; stdout.flush()?; diff --git a/src/helpers/env.rs b/src/helpers/env.rs index df440287..b13e5f06 100644 --- a/src/helpers/env.rs +++ b/src/helpers/env.rs @@ -50,7 +50,7 @@ mod tests { #[test] fn test_from_env_no_prefix() { - let desered = withenv(None, || from_env()).expect("Couldn't deser"); + let desered = withenv(None, from_env).expect("Couldn't deser"); assert_eq!( desered, Data { diff --git a/src/helpers/json.rs b/src/helpers/json.rs index 7bde457b..ef7c6fda 100644 --- a/src/helpers/json.rs +++ b/src/helpers/json.rs @@ -79,7 +79,7 @@ mod tests { use std::{fs::OpenOptions, io::Cursor}; use tempfile::{tempdir, NamedTempFile}; - const DOC: &'static str = indoc!( + const DOC: &str = indoc!( r#" { "base": "https://example.com", @@ -108,7 +108,7 @@ mod tests { #[test] fn test_from_slice() { let doc = DOC.as_bytes(); - let desered = from_slice(&doc).expect("Couldn't deserialize Data"); + let desered = from_slice(doc).expect("Couldn't deserialize Data"); assert_eq!( desered, Data { diff --git a/src/helpers/toml.rs b/src/helpers/toml.rs index abf2415b..b3f40610 100644 --- a/src/helpers/toml.rs +++ b/src/helpers/toml.rs @@ -79,7 +79,7 @@ mod tests { use std::{fs::OpenOptions, io::Cursor}; use tempfile::{tempdir, NamedTempFile}; - const DOC: &'static str = indoc!( + const DOC: &str = indoc!( r#" base = "https://example.com" client_id = "adbc01234" @@ -106,7 +106,7 @@ mod tests { #[test] fn test_from_slice() { let doc = DOC.as_bytes(); - let desered = from_slice(&doc).expect("Couldn't deserialize Data"); + let desered = from_slice(doc).expect("Couldn't deserialize Data"); assert_eq!( desered, Data { diff --git a/src/mastodon.rs b/src/mastodon.rs index ce011268..ee9e60d9 100644 --- a/src/mastodon.rs +++ b/src/mastodon.rs @@ -171,7 +171,7 @@ impl Mastodon { /// PUT /api/v1/filters/:id pub async fn update_filter(&self, id: &str, request: &mut AddFilterRequest) -> Result { - let url = self.route(format!("/api/v1/filters/{}", id)); + let url = self.route(format!("/api/v1/filters/{id}")); let response = self.client.put(&url).json(&request).send().await?; read_response(response).await @@ -207,9 +207,9 @@ impl Mastodon { pub async fn get_tagged_timeline(&self, hashtag: String, local: bool) -> Result> { let base = "/api/v1/timelines/tag/"; let url = if local { - self.route(format!("{}{}?local=1", base, hashtag)) + self.route(format!("{base}{hashtag}?local=1")) } else { - self.route(format!("{}{}", base, hashtag)) + self.route(format!("{base}{hashtag}")) }; self.get(url).await diff --git a/src/scopes.rs b/src/scopes.rs index 4ae76200..c4b5fd88 100644 --- a/src/scopes.rs +++ b/src/scopes.rs @@ -50,7 +50,7 @@ impl Serialize for Scopes { where S: Serializer, { - let repr = format!("{}", self); + let repr = format!("{self}"); serializer.serialize_str(&repr) } } @@ -178,12 +178,7 @@ impl Scopes { /// let read_write = read.and(write); /// ``` pub fn and(self, other: Scopes) -> Scopes { - let new_set: HashSet<_> = self - .scopes - .union(&other.scopes) - .into_iter() - .copied() - .collect(); + let new_set: HashSet<_> = self.scopes.union(&other.scopes).copied().collect(); Scopes { scopes: new_set } } @@ -342,7 +337,7 @@ impl fmt::Display for Scope { Follow => "follow", Push => "push", }; - write!(f, "{}", s) + write!(f, "{s}") } } @@ -419,8 +414,8 @@ impl PartialOrd for Read { impl Ord for Read { fn cmp(&self, other: &Read) -> Ordering { - let a = format!("{:?}", self); - let b = format!("{:?}", other); + let a = format!("{self:?}"); + let b = format!("{other:?}"); a.cmp(&b) } } @@ -514,8 +509,8 @@ impl PartialOrd for Write { impl Ord for Write { fn cmp(&self, other: &Write) -> Ordering { - let a = format!("{:?}", self); - let b = format!("{:?}", other); + let a = format!("{self:?}"); + let b = format!("{other:?}"); a.cmp(&b) } } From f22ee6aed4b71a74f03f3af492dafa62f4218d28 Mon Sep 17 00:00:00 2001 From: "D. Scott Boggs" Date: Fri, 20 Oct 2023 16:28:00 -0400 Subject: [PATCH 3/3] Bump rust version --- .github/workflows/rust.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index e5f9399b..db11e237 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -39,7 +39,7 @@ jobs: - uses: swatinem/rust-cache@v2 - uses: dtolnay/rust-toolchain@master with: - toolchain: 1.65.0 + toolchain: 1.67.0 components: clippy - run: cargo clippy --all-features -- -D warnings @@ -51,7 +51,7 @@ jobs: - uses: swatinem/rust-cache@v2 - uses: dtolnay/rust-toolchain@master with: - toolchain: 1.65.0 + toolchain: 1.67.0 components: rustfmt - run: cargo fmt --check