From e044246cba658945fa4e4a04564ea271cd42f214 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Sat, 4 May 2024 00:06:22 +0200 Subject: [PATCH] fixup: fmt + clippy --- src/core_api.rs | 2 +- src/error.rs | 20 +++++++++++--------- src/event_parser.rs | 4 ++-- src/event_property_parser.rs | 5 ++++- src/highlevel_api_extension.rs | 21 ++++++++++++++++----- src/ipc.rs | 8 ++++---- src/message_parser.rs | 2 +- tests/integration.rs | 2 +- tests/integration_tests/misc.rs | 2 +- tests/integration_tests/mod.rs | 4 ++-- tests/mock_socket.rs | 2 +- tests/mock_socket_tests/get_property.rs | 2 +- tests/mock_socket_tests/mod.rs | 2 +- tests/mock_socket_tests/set_property.rs | 6 +++--- 14 files changed, 49 insertions(+), 33 deletions(-) diff --git a/src/core_api.rs b/src/core_api.rs index ff2612a..92e7fee 100644 --- a/src/core_api.rs +++ b/src/core_api.rs @@ -167,7 +167,7 @@ where value: T, ) -> Result<(), MpvError> { let (res_tx, res_rx) = oneshot::channel(); - let value = serde_json::to_value(value).map_err(|why| MpvError::JsonParseError(why))?; + let value = serde_json::to_value(value).map_err(MpvError::JsonParseError)?; instance .command_sender diff --git a/src/error.rs b/src/error.rs index 0a75ccb..7adb07e 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,7 +1,7 @@ //! Library specific error messages. -use thiserror::Error; use serde_json::{Map, Value}; +use thiserror::Error; use crate::MpvDataType; @@ -22,14 +22,16 @@ pub enum MpvError { #[error("Mpv sent a value with an unexpected type:\nExpected {expected_type}, received {received:#?}")] ValueContainsUnexpectedType { - expected_type: String, - received: Value, + expected_type: String, + received: Value, }, - #[error("Mpv sent data with an unexpected type:\nExpected {expected_type}, received {received:#?}")] + #[error( + "Mpv sent data with an unexpected type:\nExpected {expected_type}, received {received:#?}" + )] DataContainsUnexpectedType { - expected_type: String, - received: MpvDataType, + expected_type: String, + received: MpvDataType, }, #[error("Missing expected 'data' field in mpv message")] @@ -37,10 +39,10 @@ pub enum MpvError { #[error("Missing key in object:\nExpected {key} in {map:#?}")] MissingKeyInObject { - key: String, - map: Map, + key: String, + map: Map, }, #[error("Unknown error: {0}")] Other(String), -} \ No newline at end of file +} diff --git a/src/event_parser.rs b/src/event_parser.rs index 8518e67..241c01f 100644 --- a/src/event_parser.rs +++ b/src/event_parser.rs @@ -292,11 +292,11 @@ fn parse_client_message(event: &Map) -> Result { fn parse_property_change(event: &Map) -> Result { let id = get_key_as!(as_u64, "id", event) as usize; let property_name = get_key_as!(as_str, "name", event); - let data = event.get("data").map(|d| json_to_value(d)).transpose()?; + let data = event.get("data").map(json_to_value).transpose()?; Ok(Event::PropertyChange { id, name: property_name.to_string(), - data: data, + data, }) } diff --git a/src/event_property_parser.rs b/src/event_property_parser.rs index c3b7d2d..bfab40a 100644 --- a/src/event_property_parser.rs +++ b/src/event_property_parser.rs @@ -34,7 +34,10 @@ pub enum Property { Speed(f64), Volume(f64), Mute(bool), - Unknown { name: String, data: Option }, + Unknown { + name: String, + data: Option, + }, } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] diff --git a/src/highlevel_api_extension.rs b/src/highlevel_api_extension.rs index 8f4b75e..4d7a4c0 100644 --- a/src/highlevel_api_extension.rs +++ b/src/highlevel_api_extension.rs @@ -1,7 +1,7 @@ //! High-level API extension for [`Mpv`]. use crate::{ - MpvError, IntoRawCommandPart, Mpv, MpvCommand, MpvDataType, Playlist, PlaylistAddOptions, + IntoRawCommandPart, Mpv, MpvCommand, MpvDataType, MpvError, Playlist, PlaylistAddOptions, PlaylistEntry, SeekOptions, }; use serde::{Deserialize, Serialize}; @@ -49,11 +49,18 @@ pub trait MpvExt { async fn stop(&self) -> Result<(), MpvError>; /// Set the volume of the player. - async fn set_volume(&self, input_volume: f64, option: NumberChangeOptions) - -> Result<(), MpvError>; + async fn set_volume( + &self, + input_volume: f64, + option: NumberChangeOptions, + ) -> Result<(), MpvError>; /// Set the playback speed of the player. - async fn set_speed(&self, input_speed: f64, option: NumberChangeOptions) -> Result<(), MpvError>; + async fn set_speed( + &self, + input_speed: f64, + option: NumberChangeOptions, + ) -> Result<(), MpvError>; /// Toggle/set the pause state of the player. async fn set_playback(&self, option: Switch) -> Result<(), MpvError>; @@ -306,7 +313,11 @@ impl MpvExt for Mpv { self.set_property("mute", enabled).await } - async fn set_speed(&self, input_speed: f64, option: NumberChangeOptions) -> Result<(), MpvError> { + async fn set_speed( + &self, + input_speed: f64, + option: NumberChangeOptions, + ) -> Result<(), MpvError> { match self.get_property::("speed").await { Ok(speed) => match option { NumberChangeOptions::Increase => { diff --git a/src/ipc.rs b/src/ipc.rs index 8531639..0310c82 100644 --- a/src/ipc.rs +++ b/src/ipc.rs @@ -56,7 +56,7 @@ impl MpvIpc { ) -> Result, MpvError> { let ipc_command = json!({ "command": command }); let ipc_command_str = - serde_json::to_string(&ipc_command).map_err(|why| MpvError::JsonParseError(why))?; + serde_json::to_string(&ipc_command).map_err(MpvError::JsonParseError)?; log::trace!("Sending command: {}", ipc_command_str); @@ -75,8 +75,8 @@ impl MpvIpc { ))? .map_err(|why| MpvError::MpvSocketConnectionError(why.to_string()))?; - let parsed_response = serde_json::from_str::(&response) - .map_err(|why| MpvError::JsonParseError(why)); + let parsed_response = + serde_json::from_str::(&response).map_err(MpvError::JsonParseError); if parsed_response .as_ref() @@ -155,7 +155,7 @@ impl MpvIpc { .map_err(|why| MpvError::MpvSocketConnectionError(why.to_string())) .and_then(|event| serde_json::from_str::(&event) - .map_err(|why| MpvError::JsonParseError(why))); + .map_err(MpvError::JsonParseError)); self.handle_event(parsed_event).await; } diff --git a/src/message_parser.rs b/src/message_parser.rs index ba335c0..3a652ba 100644 --- a/src/message_parser.rs +++ b/src/message_parser.rs @@ -152,7 +152,7 @@ pub(crate) fn json_map_to_hashmap( } pub(crate) fn json_array_to_vec(array: &[Value]) -> Result, MpvError> { - array.iter().map(|entry| json_to_value(entry)).collect() + array.iter().map(json_to_value).collect() } pub(crate) fn json_array_to_playlist(array: &[Value]) -> Vec { diff --git a/tests/integration.rs b/tests/integration.rs index 9df9e65..7822251 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -5,4 +5,4 @@ // mod misc; mod integration_tests; -// use util::*; \ No newline at end of file +// use util::*; diff --git a/tests/integration_tests/misc.rs b/tests/integration_tests/misc.rs index 8049f78..13d110b 100644 --- a/tests/integration_tests/misc.rs +++ b/tests/integration_tests/misc.rs @@ -23,4 +23,4 @@ async fn test_set_property() { mpv.kill().await.unwrap(); proc.kill().await.unwrap(); -} \ No newline at end of file +} diff --git a/tests/integration_tests/mod.rs b/tests/integration_tests/mod.rs index 212fb84..2cfc348 100644 --- a/tests/integration_tests/mod.rs +++ b/tests/integration_tests/mod.rs @@ -1,5 +1,5 @@ mod event_property_parser; -mod util; mod misc; +mod util; -use util::*; \ No newline at end of file +use util::*; diff --git a/tests/mock_socket.rs b/tests/mock_socket.rs index 2fac2b4..f3f8950 100644 --- a/tests/mock_socket.rs +++ b/tests/mock_socket.rs @@ -1 +1 @@ -mod mock_socket_tests; \ No newline at end of file +mod mock_socket_tests; diff --git a/tests/mock_socket_tests/get_property.rs b/tests/mock_socket_tests/get_property.rs index 3a3b0b0..815e89a 100644 --- a/tests/mock_socket_tests/get_property.rs +++ b/tests/mock_socket_tests/get_property.rs @@ -1,7 +1,7 @@ use std::{panic, time::Duration}; use futures::{stream::FuturesUnordered, SinkExt, StreamExt}; -use mpvipc::{MpvError, Mpv, MpvExt, Playlist, PlaylistEntry}; +use mpvipc::{Mpv, MpvError, MpvExt, Playlist, PlaylistEntry}; use serde_json::{json, Value}; use test_log::test; use tokio::{net::UnixStream, task::JoinHandle}; diff --git a/tests/mock_socket_tests/mod.rs b/tests/mock_socket_tests/mod.rs index c50d4ee..f9b88d0 100644 --- a/tests/mock_socket_tests/mod.rs +++ b/tests/mock_socket_tests/mod.rs @@ -1,3 +1,3 @@ mod events; mod get_property; -mod set_property; \ No newline at end of file +mod set_property; diff --git a/tests/mock_socket_tests/set_property.rs b/tests/mock_socket_tests/set_property.rs index 22b249f..79b1a51 100644 --- a/tests/mock_socket_tests/set_property.rs +++ b/tests/mock_socket_tests/set_property.rs @@ -1,7 +1,7 @@ use std::{panic, time::Duration}; use futures::{stream::FuturesUnordered, SinkExt, StreamExt}; -use mpvipc::{MpvError, Mpv, MpvExt, Playlist, PlaylistEntry}; +use mpvipc::{Mpv, MpvError, MpvExt, Playlist, PlaylistEntry}; use serde_json::{json, Value}; use test_log::test; use tokio::{net::UnixStream, task::JoinHandle}; @@ -130,7 +130,7 @@ async fn test_set_property_simultaneous_requests() { loop { let status = mpv_clone_1.set_property("volume", 100).await; match status { - Ok(()) => {}, + Ok(()) => {} _ => panic!("Unexpected result: {:?}", status), } } @@ -142,7 +142,7 @@ async fn test_set_property_simultaneous_requests() { tokio::time::sleep(Duration::from_millis(1)).await; let status = mpv_clone_2.set_property("pause", false).await; match status { - Ok(()) => {}, + Ok(()) => {} _ => panic!("Unexpected result: {:?}", status), } }