fixup: fmt + clippy

This commit is contained in:
Oystein Kristoffer Tveit 2024-05-04 00:06:22 +02:00
parent f1687fe07b
commit e044246cba
Signed by: oysteikt
GPG Key ID: 9F2F7D8250F35146
14 changed files with 49 additions and 33 deletions

View File

@ -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

View File

@ -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,8 +39,8 @@ pub enum MpvError {
#[error("Missing key in object:\nExpected {key} in {map:#?}")]
MissingKeyInObject {
key: String,
map: Map<String, Value>,
key: String,
map: Map<String, Value>,
},
#[error("Unknown error: {0}")]

View File

@ -292,11 +292,11 @@ fn parse_client_message(event: &Map<String, Value>) -> Result<Event, MpvError> {
fn parse_property_change(event: &Map<String, Value>) -> Result<Event, MpvError> {
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,
})
}

View File

@ -34,7 +34,10 @@ pub enum Property {
Speed(f64),
Volume(f64),
Mute(bool),
Unknown { name: String, data: Option<MpvDataType> },
Unknown {
name: String,
data: Option<MpvDataType>,
},
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]

View File

@ -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::<f64>("speed").await {
Ok(speed) => match option {
NumberChangeOptions::Increase => {

View File

@ -56,7 +56,7 @@ impl MpvIpc {
) -> Result<Option<Value>, 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::<Value>(&response)
.map_err(|why| MpvError::JsonParseError(why));
let parsed_response =
serde_json::from_str::<Value>(&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::<Value>(&event)
.map_err(|why| MpvError::JsonParseError(why)));
.map_err(MpvError::JsonParseError));
self.handle_event(parsed_event).await;
}

View File

@ -152,7 +152,7 @@ pub(crate) fn json_map_to_hashmap(
}
pub(crate) fn json_array_to_vec(array: &[Value]) -> Result<Vec<MpvDataType>, 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<PlaylistEntry> {

View File

@ -1,5 +1,5 @@
mod event_property_parser;
mod util;
mod misc;
mod util;
use util::*;

View File

@ -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};

View File

@ -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),
}
}