cargo fmt + clippy
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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<Self::Response, ResponseParserError<'_>> {
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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<Self::Response, ResponseParserError<'_>> {
|
||||
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::<Result<Vec<_>, ResponseParserError>>()?;
|
||||
let list = parts
|
||||
.0
|
||||
.into_iter()
|
||||
.map(|(k, v)| Ok(expect_property_type!(Some(v), k, Text).to_string()))
|
||||
.collect::<Result<Vec<_>, ResponseParserError>>()?;
|
||||
|
||||
Ok(list)
|
||||
Ok(list)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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::<Vec<String>>();
|
||||
let features = parts.map(|s| s.to_string()).collect::<Vec<String>>();
|
||||
|
||||
Ok((Request::ProtocolDisable(features), ""))
|
||||
}
|
||||
|
||||
@@ -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::<Vec<String>>();
|
||||
let features = parts.map(|s| s.to_string()).collect::<Vec<String>>();
|
||||
|
||||
Ok((Request::ProtocolEnable(features), ""))
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::commands::{
|
||||
Command, GenericResponseValue, Request, RequestParserResult, ResponseAttributes,
|
||||
Command, Request, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError, expect_property_type,
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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::<Vec<String>>();
|
||||
let tag_types = parts.map(|s| s.to_string()).collect::<Vec<String>>();
|
||||
|
||||
Ok((Request::TagTypesDisable(tag_types), ""))
|
||||
}
|
||||
|
||||
@@ -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::<Vec<String>>();
|
||||
let tag_types = parts.map(|s| s.to_string()).collect::<Vec<String>>();
|
||||
|
||||
Ok((Request::TagTypesEnable(tag_types), ""))
|
||||
}
|
||||
|
||||
@@ -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::<Vec<String>>();
|
||||
let tag_types = parts.map(|s| s.to_string()).collect::<Vec<String>>();
|
||||
|
||||
Ok((Request::TagTypesReset(tag_types), ""))
|
||||
}
|
||||
|
||||
@@ -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<Self::Response, ResponseParserError<'_>> {
|
||||
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(),]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Self::Response, ResponseParserError<'_>> {
|
||||
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);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::commands::{
|
||||
Command, GenericResponseValue, Request, RequestParserResult, ResponseAttributes,
|
||||
Command, Request, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError, expect_property_type,
|
||||
};
|
||||
|
||||
|
||||
@@ -73,7 +73,6 @@ impl Command for Decoders {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use indoc::indoc;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -33,8 +33,8 @@ impl Command for StickerList {
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
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
|
||||
|
||||
@@ -20,7 +20,7 @@ impl Command for StickerNames {
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -20,7 +20,7 @@ impl Command for StickerTypes {
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
@@ -30,9 +30,6 @@ impl FromStr for TimeInterval {
|
||||
debug_assert!(start <= end);
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
start: start,
|
||||
end: end,
|
||||
})
|
||||
Ok(Self { start, end })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 })
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user