fixup: fmt + clippy
This commit is contained in:
parent
43e88d6224
commit
5100224a26
|
@ -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
|
||||
|
|
20
src/error.rs
20
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<String, Value>,
|
||||
key: String,
|
||||
map: Map<String, Value>,
|
||||
},
|
||||
|
||||
#[error("Unknown error: {0}")]
|
||||
Other(String),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -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 => {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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> {
|
||||
|
|
|
@ -5,4 +5,4 @@
|
|||
// mod misc;
|
||||
mod integration_tests;
|
||||
|
||||
// use util::*;
|
||||
// use util::*;
|
||||
|
|
|
@ -23,4 +23,4 @@ async fn test_set_property() {
|
|||
|
||||
mpv.kill().await.unwrap();
|
||||
proc.kill().await.unwrap();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
mod event_property_parser;
|
||||
mod util;
|
||||
mod misc;
|
||||
mod util;
|
||||
|
||||
use util::*;
|
||||
use util::*;
|
||||
|
|
|
@ -1 +1 @@
|
|||
mod mock_socket_tests;
|
||||
mod mock_socket_tests;
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
mod events;
|
||||
mod get_property;
|
||||
mod set_property;
|
||||
mod set_property;
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue