From f65760314f8922065654c065be4bbdcf0cb4b515 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Fri, 21 Nov 2025 16:02:15 +0900 Subject: [PATCH] cargo fmt + clippy --- src/commands/audio_output_devices/outputs.rs | 4 +-- src/commands/connection_settings/protocol.rs | 7 ++-- .../connection_settings/protocol_available.rs | 23 +++++++------ .../connection_settings/protocol_disable.rs | 5 +-- .../connection_settings/protocol_enable.rs | 5 +-- src/commands/connection_settings/tag_types.rs | 2 +- .../tag_types_available.rs | 5 ++- .../connection_settings/tag_types_disable.rs | 5 +-- .../connection_settings/tag_types_enable.rs | 5 +-- .../connection_settings/tag_types_reset.rs | 5 +-- .../mounts_and_neighbors/listmounts.rs | 33 +++++++++---------- .../mounts_and_neighbors/listneighbors.rs | 7 ++-- src/commands/reflection/commands.rs | 2 +- src/commands/reflection/decoders.rs | 1 - src/commands/reflection/not_commands.rs | 3 +- src/commands/reflection/url_handlers.rs | 3 +- src/commands/stickers/sticker_find.rs | 3 +- src/commands/stickers/sticker_list.rs | 4 +-- src/commands/stickers/stickernames.rs | 2 +- src/commands/stickers/stickernamestypes.rs | 3 +- src/commands/stickers/stickertypes.rs | 2 +- src/commands/stored_playlists/listplaylist.rs | 4 +-- src/common/types/time_interval.rs | 5 +-- src/common/types/window_range.rs | 2 +- 24 files changed, 67 insertions(+), 73 deletions(-) diff --git a/src/commands/audio_output_devices/outputs.rs b/src/commands/audio_output_devices/outputs.rs index ba72e29..90544c3 100644 --- a/src/commands/audio_output_devices/outputs.rs +++ b/src/commands/audio_output_devices/outputs.rs @@ -80,11 +80,11 @@ impl Command for Outputs { let mut parts = value.splitn(2, '='); let attr_key = parts .next() - .ok_or(ResponseParserError::SyntaxError(0, &value))? + .ok_or(ResponseParserError::SyntaxError(0, value))? .to_string(); let attr_value = parts .next() - .ok_or(ResponseParserError::SyntaxError(0, &value))? + .ok_or(ResponseParserError::SyntaxError(0, value))? .to_string(); attributes.insert(attr_key, attr_value); } diff --git a/src/commands/connection_settings/protocol.rs b/src/commands/connection_settings/protocol.rs index 95212ca..aa45bc1 100644 --- a/src/commands/connection_settings/protocol.rs +++ b/src/commands/connection_settings/protocol.rs @@ -1,5 +1,8 @@ use crate::{ - commands::{expect_property_type, Command, RequestParserResult, ResponseAttributes, ResponseParserError}, Request + Request, + commands::{ + Command, RequestParserResult, ResponseAttributes, ResponseParserError, expect_property_type, + }, }; pub struct Protocol; @@ -18,7 +21,7 @@ impl Command for Protocol { fn parse_response( parts: ResponseAttributes<'_>, ) -> Result> { - for (k, _) in parts.0.iter().filter(|(k, _)| *k != "feature") { + if let Some((k, _)) = parts.0.iter().find(|(k, _)| *k != "feature") { return Err(ResponseParserError::UnexpectedProperty(k)); } diff --git a/src/commands/connection_settings/protocol_available.rs b/src/commands/connection_settings/protocol_available.rs index 3cc133f..a98c7f8 100644 --- a/src/commands/connection_settings/protocol_available.rs +++ b/src/commands/connection_settings/protocol_available.rs @@ -1,5 +1,8 @@ use crate::{ - commands::{expect_property_type, Command, RequestParserResult, ResponseAttributes, ResponseParserError}, Request + Request, + commands::{ + Command, RequestParserResult, ResponseAttributes, ResponseParserError, expect_property_type, + }, }; pub struct ProtocolAvailable; @@ -18,16 +21,16 @@ impl Command for ProtocolAvailable { fn parse_response( parts: ResponseAttributes<'_>, ) -> Result> { - for (k, _) in parts.0.iter().filter(|(k, _)| *k != "feature") { - return Err(ResponseParserError::UnexpectedProperty(k)); - } + if let Some((k, _)) = parts.0.iter().find(|(k, _)| *k != "feature") { + return Err(ResponseParserError::UnexpectedProperty(k)); + } - let list = parts - .0 - .into_iter() - .map(|(k, v)| Ok(expect_property_type!(Some(v), k, Text).to_string())) - .collect::, ResponseParserError>>()?; + let list = parts + .0 + .into_iter() + .map(|(k, v)| Ok(expect_property_type!(Some(v), k, Text).to_string())) + .collect::, ResponseParserError>>()?; - Ok(list) + Ok(list) } } diff --git a/src/commands/connection_settings/protocol_disable.rs b/src/commands/connection_settings/protocol_disable.rs index d1cdaf6..c547ce6 100644 --- a/src/commands/connection_settings/protocol_disable.rs +++ b/src/commands/connection_settings/protocol_disable.rs @@ -18,10 +18,7 @@ impl Command for ProtocolDisable { } // TODO: verify that the features are split by whitespace - let features = parts - .into_iter() - .map(|s| s.to_string()) - .collect::>(); + let features = parts.map(|s| s.to_string()).collect::>(); Ok((Request::ProtocolDisable(features), "")) } diff --git a/src/commands/connection_settings/protocol_enable.rs b/src/commands/connection_settings/protocol_enable.rs index 7236c7a..fe463f0 100644 --- a/src/commands/connection_settings/protocol_enable.rs +++ b/src/commands/connection_settings/protocol_enable.rs @@ -18,10 +18,7 @@ impl Command for ProtocolEnable { } // TODO: verify that the features are split by whitespace - let features = parts - .into_iter() - .map(|s| s.to_string()) - .collect::>(); + let features = parts.map(|s| s.to_string()).collect::>(); Ok((Request::ProtocolEnable(features), "")) } diff --git a/src/commands/connection_settings/tag_types.rs b/src/commands/connection_settings/tag_types.rs index 3c43511..236a09d 100644 --- a/src/commands/connection_settings/tag_types.rs +++ b/src/commands/connection_settings/tag_types.rs @@ -1,5 +1,5 @@ use crate::commands::{ - Command, GenericResponseValue, Request, RequestParserResult, ResponseAttributes, + Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError, expect_property_type, }; diff --git a/src/commands/connection_settings/tag_types_available.rs b/src/commands/connection_settings/tag_types_available.rs index 7be954f..89156fe 100644 --- a/src/commands/connection_settings/tag_types_available.rs +++ b/src/commands/connection_settings/tag_types_available.rs @@ -1,5 +1,8 @@ use crate::{ - commands::{expect_property_type, Command, RequestParserResult, ResponseAttributes, ResponseParserError}, Request + Request, + commands::{ + Command, RequestParserResult, ResponseAttributes, ResponseParserError, expect_property_type, + }, }; pub struct TagTypesAvailable; diff --git a/src/commands/connection_settings/tag_types_disable.rs b/src/commands/connection_settings/tag_types_disable.rs index 785a08b..6aa6197 100644 --- a/src/commands/connection_settings/tag_types_disable.rs +++ b/src/commands/connection_settings/tag_types_disable.rs @@ -18,10 +18,7 @@ impl Command for TagTypesDisable { } // TODO: verify that the tag types are split by whitespace - let tag_types = parts - .into_iter() - .map(|s| s.to_string()) - .collect::>(); + let tag_types = parts.map(|s| s.to_string()).collect::>(); Ok((Request::TagTypesDisable(tag_types), "")) } diff --git a/src/commands/connection_settings/tag_types_enable.rs b/src/commands/connection_settings/tag_types_enable.rs index 1292572..7580ef9 100644 --- a/src/commands/connection_settings/tag_types_enable.rs +++ b/src/commands/connection_settings/tag_types_enable.rs @@ -18,10 +18,7 @@ impl Command for TagTypesEnable { } // TODO: verify that the tag types are split by whitespace - let tag_types = parts - .into_iter() - .map(|s| s.to_string()) - .collect::>(); + let tag_types = parts.map(|s| s.to_string()).collect::>(); Ok((Request::TagTypesEnable(tag_types), "")) } diff --git a/src/commands/connection_settings/tag_types_reset.rs b/src/commands/connection_settings/tag_types_reset.rs index b63276f..049f1a5 100644 --- a/src/commands/connection_settings/tag_types_reset.rs +++ b/src/commands/connection_settings/tag_types_reset.rs @@ -18,10 +18,7 @@ impl Command for TagTypesReset { } // TODO: verify that the tag types are split by whitespace - let tag_types = parts - .into_iter() - .map(|s| s.to_string()) - .collect::>(); + let tag_types = parts.map(|s| s.to_string()).collect::>(); Ok((Request::TagTypesReset(tag_types), "")) } diff --git a/src/commands/mounts_and_neighbors/listmounts.rs b/src/commands/mounts_and_neighbors/listmounts.rs index 640cac2..96a2e58 100644 --- a/src/commands/mounts_and_neighbors/listmounts.rs +++ b/src/commands/mounts_and_neighbors/listmounts.rs @@ -1,5 +1,8 @@ use crate::{ - commands::{expect_property_type, Command, RequestParserResult, ResponseAttributes, ResponseParserError}, Request + Request, + commands::{ + Command, RequestParserResult, ResponseAttributes, ResponseParserError, expect_property_type, + }, }; pub struct ListMounts; @@ -16,16 +19,16 @@ impl Command for ListMounts { fn parse_response( parts: ResponseAttributes<'_>, ) -> Result> { - let parts: Vec<_> = parts.into(); - let mut result = Vec::with_capacity(parts.len()); - for (key, value) in parts.into_iter() { - if key != "mount" { - return Err(ResponseParserError::UnexpectedProperty(key)); - } - let value = expect_property_type!(Some(value), "mount", Text).to_string(); - result.push(value); - } - Ok(result) + let parts: Vec<_> = parts.into(); + let mut result = Vec::with_capacity(parts.len()); + for (key, value) in parts.into_iter() { + if key != "mount" { + return Err(ResponseParserError::UnexpectedProperty(key)); + } + let value = expect_property_type!(Some(value), "mount", Text).to_string(); + result.push(value); + } + Ok(result) } } @@ -43,12 +46,6 @@ mod tests { OK "}; let result = ListMounts::parse_raw_response(input); - assert_eq!( - result, - Ok(vec![ - "".to_string(), - "/mnt/music".to_string(), - ]) - ); + assert_eq!(result, Ok(vec!["".to_string(), "/mnt/music".to_string(),])); } } diff --git a/src/commands/mounts_and_neighbors/listneighbors.rs b/src/commands/mounts_and_neighbors/listneighbors.rs index ac059fe..098feac 100644 --- a/src/commands/mounts_and_neighbors/listneighbors.rs +++ b/src/commands/mounts_and_neighbors/listneighbors.rs @@ -1,7 +1,10 @@ use std::collections::HashMap; use crate::{ - commands::{expect_property_type, Command, RequestParserResult, ResponseAttributes, ResponseParserError}, Request + Request, + commands::{ + Command, RequestParserResult, ResponseAttributes, ResponseParserError, expect_property_type, + }, }; pub struct ListNeighbors; @@ -20,7 +23,7 @@ impl Command for ListNeighbors { fn parse_response( parts: ResponseAttributes<'_>, ) -> Result> { - let parts: Vec<_> = parts.into(); + let parts: Vec<_> = parts.into(); debug_assert!(parts.len() % 2 == 0); let mut result = HashMap::with_capacity(parts.len() / 2); diff --git a/src/commands/reflection/commands.rs b/src/commands/reflection/commands.rs index 428ab82..f117408 100644 --- a/src/commands/reflection/commands.rs +++ b/src/commands/reflection/commands.rs @@ -1,5 +1,5 @@ use crate::commands::{ - Command, GenericResponseValue, Request, RequestParserResult, ResponseAttributes, + Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError, expect_property_type, }; diff --git a/src/commands/reflection/decoders.rs b/src/commands/reflection/decoders.rs index 07722fa..fe5a6a0 100644 --- a/src/commands/reflection/decoders.rs +++ b/src/commands/reflection/decoders.rs @@ -73,7 +73,6 @@ impl Command for Decoders { } } - #[cfg(test)] mod tests { use indoc::indoc; diff --git a/src/commands/reflection/not_commands.rs b/src/commands/reflection/not_commands.rs index 98b07f7..b0b088a 100644 --- a/src/commands/reflection/not_commands.rs +++ b/src/commands/reflection/not_commands.rs @@ -1,5 +1,6 @@ use crate::commands::{ - expect_property_type, Command, GenericResponseValue, Request, RequestParserResult, ResponseAttributes, ResponseParserError + Command, Request, RequestParserResult, ResponseAttributes, + ResponseParserError, expect_property_type, }; pub struct NotCommands; diff --git a/src/commands/reflection/url_handlers.rs b/src/commands/reflection/url_handlers.rs index b849ba1..27bf5a5 100644 --- a/src/commands/reflection/url_handlers.rs +++ b/src/commands/reflection/url_handlers.rs @@ -1,5 +1,6 @@ use crate::commands::{ - expect_property_type, Command, GenericResponseValue, Request, RequestParserResult, ResponseAttributes, ResponseParserError + Command, Request, RequestParserResult, ResponseAttributes, + ResponseParserError, expect_property_type, }; pub struct UrlHandlers; diff --git a/src/commands/stickers/sticker_find.rs b/src/commands/stickers/sticker_find.rs index d6fb576..a3c3b78 100644 --- a/src/commands/stickers/sticker_find.rs +++ b/src/commands/stickers/sticker_find.rs @@ -1,7 +1,8 @@ use serde::{Deserialize, Serialize}; use crate::commands::{ - expect_property_type, Command, GenericResponseValue, Request, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError + Command, Request, RequestParserError, RequestParserResult, ResponseAttributes, + ResponseParserError, expect_property_type, }; pub struct StickerFind; diff --git a/src/commands/stickers/sticker_list.rs b/src/commands/stickers/sticker_list.rs index f966c9a..9360fe8 100644 --- a/src/commands/stickers/sticker_list.rs +++ b/src/commands/stickers/sticker_list.rs @@ -33,8 +33,8 @@ impl Command for StickerList { parts: ResponseAttributes<'_>, ) -> Result> { let parts: Vec<_> = parts.into(); - for part in parts.iter().filter(|part| part.0 != "sticker") { - return Err(ResponseParserError::UnexpectedProperty(part.0)); + if let Some((k, _)) = parts.iter().find(|(k, _)| *k != "sticker") { + return Err(ResponseParserError::UnexpectedProperty(k)); } let result = parts diff --git a/src/commands/stickers/stickernames.rs b/src/commands/stickers/stickernames.rs index aae9e3c..d61515a 100644 --- a/src/commands/stickers/stickernames.rs +++ b/src/commands/stickers/stickernames.rs @@ -20,7 +20,7 @@ impl Command for StickerNames { fn parse_response( parts: ResponseAttributes<'_>, ) -> Result> { - for (k, _) in parts.0.iter().filter(|(k, _)| *k != "name") { + if let Some((k, _)) = parts.0.iter().find(|(k, _)| *k != "name") { return Err(ResponseParserError::UnexpectedProperty(k)); } diff --git a/src/commands/stickers/stickernamestypes.rs b/src/commands/stickers/stickernamestypes.rs index 9d08f3a..055bac5 100644 --- a/src/commands/stickers/stickernamestypes.rs +++ b/src/commands/stickers/stickernamestypes.rs @@ -1,7 +1,8 @@ use std::collections::HashMap; use crate::commands::{ - expect_property_type, Command, GenericResponseValue, Request, RequestParserResult, ResponseAttributes, ResponseParserError + Command, Request, RequestParserResult, ResponseAttributes, + ResponseParserError, expect_property_type, }; pub struct StickerNamesTypes; diff --git a/src/commands/stickers/stickertypes.rs b/src/commands/stickers/stickertypes.rs index b79f3af..2c4d00d 100644 --- a/src/commands/stickers/stickertypes.rs +++ b/src/commands/stickers/stickertypes.rs @@ -20,7 +20,7 @@ impl Command for StickerTypes { fn parse_response( parts: ResponseAttributes<'_>, ) -> Result> { - for (k, _) in parts.0.iter().filter(|(k, _)| *k != "stickertype") { + if let Some((k, _)) = parts.0.iter().find(|(k, _)| *k != "stickertype") { return Err(ResponseParserError::UnexpectedProperty(k)); } diff --git a/src/commands/stored_playlists/listplaylist.rs b/src/commands/stored_playlists/listplaylist.rs index 1138980..f0c512f 100644 --- a/src/commands/stored_playlists/listplaylist.rs +++ b/src/commands/stored_playlists/listplaylist.rs @@ -1,7 +1,7 @@ use crate::{ commands::{ - Command, Request, RequestParserError, RequestParserResult, - ResponseAttributes, ResponseParserError, expect_property_type, + Command, Request, RequestParserError, RequestParserResult, ResponseAttributes, + ResponseParserError, expect_property_type, }, common::PlaylistName, }; diff --git a/src/common/types/time_interval.rs b/src/common/types/time_interval.rs index a0526ff..416ec87 100644 --- a/src/common/types/time_interval.rs +++ b/src/common/types/time_interval.rs @@ -30,9 +30,6 @@ impl FromStr for TimeInterval { debug_assert!(start <= end); } - Ok(Self { - start: start, - end: end, - }) + Ok(Self { start, end }) } } diff --git a/src/common/types/window_range.rs b/src/common/types/window_range.rs index 59a5c34..5fddb5e 100644 --- a/src/common/types/window_range.rs +++ b/src/common/types/window_range.rs @@ -23,6 +23,6 @@ impl FromStr for WindowRange { debug_assert!(end.is_none_or(|end| end >= start)); - Ok(Self { start, end: end }) + Ok(Self { start, end }) } }