diff --git a/src/client.rs b/src/client.rs index a0c53798..d596147f 100644 --- a/src/client.rs +++ b/src/client.rs @@ -51,7 +51,7 @@ where .await .map_err(MpdClientError::ConnectionError)?; - return Ok(version_line.trim().to_string()); + Ok(version_line.trim().to_string()) } async fn read_response(&mut self) -> Result, MpdClientError> { diff --git a/src/commands.rs b/src/commands.rs index 1e9197b3..533e0d75 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -179,45 +179,45 @@ pub trait Command { Self: Sized, T: AsyncWrite + AsyncRead + Unpin, { - let payload = request.serialize(); + let payload = request.serialize(); - connection - .write_all(payload.as_bytes()) - .await - .map_err(crate::MpdClientError::ConnectionError)?; + connection + .write_all(payload.as_bytes()) + .await + .map_err(crate::MpdClientError::ConnectionError)?; - connection - .flush() - .await - .map_err(crate::MpdClientError::ConnectionError)?; + connection + .flush() + .await + .map_err(crate::MpdClientError::ConnectionError)?; - let mut response_bytes = Vec::new(); - let mut reader = BufReader::new(connection); + let mut response_bytes = Vec::new(); + let mut reader = BufReader::new(connection); - loop { - let mut line = Vec::new(); + loop { + let mut line = Vec::new(); - let bytes_read = reader - .read_until(b'\n', &mut line) - .await - .map_err(crate::MpdClientError::ConnectionError)?; + let bytes_read = reader + .read_until(b'\n', &mut line) + .await + .map_err(crate::MpdClientError::ConnectionError)?; - if bytes_read == 0 { - break; // EOF reached - } + if bytes_read == 0 { + break; // EOF reached + } - response_bytes.extend_from_slice(&line); + response_bytes.extend_from_slice(&line); - // TODO: handle errors properly - if line == b"OK\n" || line.starts_with(b"ACK ") { - break; // End of response - } - } + // TODO: handle errors properly + if line == b"OK\n" || line.starts_with(b"ACK ") { + break; // End of response + } + } - let response = Self::parse_raw_response(&response_bytes) - .map_err(crate::MpdClientError::ResponseParseError)?; + let response = Self::parse_raw_response(&response_bytes) + .map_err(crate::MpdClientError::ResponseParseError)?; - Ok(response) + Ok(response) } } @@ -505,7 +505,6 @@ pub enum RequestParserError { #[error("Request ended early, while more arguments were expected")] UnexpectedEOF, - // #[error("Request is missing terminating newline")] // MissingNewline, } @@ -537,7 +536,6 @@ pub enum ResponseParserError { #[error("Response ended early, while more properties were expected")] UnexpectedEOF, - // #[error("Response is missing terminating newline")] // MissingNewline, } diff --git a/src/commands/music_database/listall.rs b/src/commands/music_database/listall.rs index e29bcc81..23e25479 100644 --- a/src/commands/music_database/listall.rs +++ b/src/commands/music_database/listall.rs @@ -2,8 +2,7 @@ use serde::{Deserialize, Serialize}; use crate::{ commands::{ - Command, CommandResponse, ResponseParserError, - single_optional_item_command_request, + Command, CommandResponse, ResponseParserError, single_optional_item_command_request, }, response_tokenizer::ResponseAttributes, types::{DbSelectionPrintResponse, Uri}, diff --git a/src/commands/music_database/listallinfo.rs b/src/commands/music_database/listallinfo.rs index 99aa33cc..66760ae8 100644 --- a/src/commands/music_database/listallinfo.rs +++ b/src/commands/music_database/listallinfo.rs @@ -2,8 +2,7 @@ use serde::{Deserialize, Serialize}; use crate::{ commands::{ - Command, CommandResponse, ResponseParserError, - single_optional_item_command_request, + Command, CommandResponse, ResponseParserError, single_optional_item_command_request, }, response_tokenizer::ResponseAttributes, types::{DbSelectionPrintResponse, Uri}, diff --git a/src/commands/music_database/listfiles.rs b/src/commands/music_database/listfiles.rs index f5eb1832..90cbd1d9 100644 --- a/src/commands/music_database/listfiles.rs +++ b/src/commands/music_database/listfiles.rs @@ -2,8 +2,7 @@ use serde::{Deserialize, Serialize}; use crate::{ commands::{ - Command, CommandResponse, ResponseParserError, - single_optional_item_command_request, + Command, CommandResponse, ResponseParserError, single_optional_item_command_request, }, response_tokenizer::ResponseAttributes, types::{DbDirectoryInfo, DbSelectionPrintResponse, Uri}, diff --git a/src/commands/music_database/lsinfo.rs b/src/commands/music_database/lsinfo.rs index 2e858cc7..65a9c095 100644 --- a/src/commands/music_database/lsinfo.rs +++ b/src/commands/music_database/lsinfo.rs @@ -2,8 +2,7 @@ use serde::{Deserialize, Serialize}; use crate::{ commands::{ - Command, CommandResponse, ResponseParserError, - single_optional_item_command_request, + Command, CommandResponse, ResponseParserError, single_optional_item_command_request, }, response_tokenizer::ResponseAttributes, types::{DbSelectionPrintResponse, Uri}, diff --git a/src/commands/music_database/rescan.rs b/src/commands/music_database/rescan.rs index ff8ea813..ae3c04f5 100644 --- a/src/commands/music_database/rescan.rs +++ b/src/commands/music_database/rescan.rs @@ -4,8 +4,7 @@ use serde::{Deserialize, Serialize}; use crate::{ commands::{ - Command, CommandResponse, ResponseParserError, - single_optional_item_command_request, + Command, CommandResponse, ResponseParserError, single_optional_item_command_request, }, response_tokenizer::{ResponseAttributes, get_and_parse_property}, types::Uri, diff --git a/src/commands/music_database/update.rs b/src/commands/music_database/update.rs index 74d93eff..d4833cc7 100644 --- a/src/commands/music_database/update.rs +++ b/src/commands/music_database/update.rs @@ -4,8 +4,7 @@ use serde::{Deserialize, Serialize}; use crate::{ commands::{ - Command, CommandResponse, ResponseParserError, - single_optional_item_command_request, + Command, CommandResponse, ResponseParserError, single_optional_item_command_request, }, response_tokenizer::{ResponseAttributes, get_and_parse_property}, types::Uri, diff --git a/src/commands/queue/playlistinfo.rs b/src/commands/queue/playlistinfo.rs index 812a6ad5..a753d985 100644 --- a/src/commands/queue/playlistinfo.rs +++ b/src/commands/queue/playlistinfo.rs @@ -2,8 +2,7 @@ use serde::{Deserialize, Serialize}; use crate::{ commands::{ - Command, CommandResponse, ResponseParserError, - single_optional_item_command_request, + Command, CommandResponse, ResponseParserError, single_optional_item_command_request, }, response_tokenizer::ResponseAttributes, types::{DbSongInfo, OneOrRange, Priority, SongId, SongPosition}, diff --git a/src/commands/queue/shuffle.rs b/src/commands/queue/shuffle.rs index d2822fae..80e0e2e2 100644 --- a/src/commands/queue/shuffle.rs +++ b/src/commands/queue/shuffle.rs @@ -1,7 +1,5 @@ use crate::{ - commands::{ - Command, empty_command_response, single_optional_item_command_request, - }, + commands::{Command, empty_command_response, single_optional_item_command_request}, types::OneOrRange, };