fixup: fmt + clippy
This commit is contained in:
parent
f1687fe07b
commit
e044246cba
|
@ -167,7 +167,7 @@ where
|
||||||
value: T,
|
value: T,
|
||||||
) -> Result<(), MpvError> {
|
) -> Result<(), MpvError> {
|
||||||
let (res_tx, res_rx) = oneshot::channel();
|
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
|
instance
|
||||||
.command_sender
|
.command_sender
|
||||||
|
|
20
src/error.rs
20
src/error.rs
|
@ -1,7 +1,7 @@
|
||||||
//! Library specific error messages.
|
//! Library specific error messages.
|
||||||
|
|
||||||
use thiserror::Error;
|
|
||||||
use serde_json::{Map, Value};
|
use serde_json::{Map, Value};
|
||||||
|
use thiserror::Error;
|
||||||
|
|
||||||
use crate::MpvDataType;
|
use crate::MpvDataType;
|
||||||
|
|
||||||
|
@ -22,14 +22,16 @@ pub enum MpvError {
|
||||||
|
|
||||||
#[error("Mpv sent a value with an unexpected type:\nExpected {expected_type}, received {received:#?}")]
|
#[error("Mpv sent a value with an unexpected type:\nExpected {expected_type}, received {received:#?}")]
|
||||||
ValueContainsUnexpectedType {
|
ValueContainsUnexpectedType {
|
||||||
expected_type: String,
|
expected_type: String,
|
||||||
received: Value,
|
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 {
|
DataContainsUnexpectedType {
|
||||||
expected_type: String,
|
expected_type: String,
|
||||||
received: MpvDataType,
|
received: MpvDataType,
|
||||||
},
|
},
|
||||||
|
|
||||||
#[error("Missing expected 'data' field in mpv message")]
|
#[error("Missing expected 'data' field in mpv message")]
|
||||||
|
@ -37,10 +39,10 @@ pub enum MpvError {
|
||||||
|
|
||||||
#[error("Missing key in object:\nExpected {key} in {map:#?}")]
|
#[error("Missing key in object:\nExpected {key} in {map:#?}")]
|
||||||
MissingKeyInObject {
|
MissingKeyInObject {
|
||||||
key: String,
|
key: String,
|
||||||
map: Map<String, Value>,
|
map: Map<String, Value>,
|
||||||
},
|
},
|
||||||
|
|
||||||
#[error("Unknown error: {0}")]
|
#[error("Unknown error: {0}")]
|
||||||
Other(String),
|
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> {
|
fn parse_property_change(event: &Map<String, Value>) -> Result<Event, MpvError> {
|
||||||
let id = get_key_as!(as_u64, "id", event) as usize;
|
let id = get_key_as!(as_u64, "id", event) as usize;
|
||||||
let property_name = get_key_as!(as_str, "name", event);
|
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 {
|
Ok(Event::PropertyChange {
|
||||||
id,
|
id,
|
||||||
name: property_name.to_string(),
|
name: property_name.to_string(),
|
||||||
data: data,
|
data,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,10 @@ pub enum Property {
|
||||||
Speed(f64),
|
Speed(f64),
|
||||||
Volume(f64),
|
Volume(f64),
|
||||||
Mute(bool),
|
Mute(bool),
|
||||||
Unknown { name: String, data: Option<MpvDataType> },
|
Unknown {
|
||||||
|
name: String,
|
||||||
|
data: Option<MpvDataType>,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//! High-level API extension for [`Mpv`].
|
//! High-level API extension for [`Mpv`].
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
MpvError, IntoRawCommandPart, Mpv, MpvCommand, MpvDataType, Playlist, PlaylistAddOptions,
|
IntoRawCommandPart, Mpv, MpvCommand, MpvDataType, MpvError, Playlist, PlaylistAddOptions,
|
||||||
PlaylistEntry, SeekOptions,
|
PlaylistEntry, SeekOptions,
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
@ -49,11 +49,18 @@ pub trait MpvExt {
|
||||||
async fn stop(&self) -> Result<(), MpvError>;
|
async fn stop(&self) -> Result<(), MpvError>;
|
||||||
|
|
||||||
/// Set the volume of the player.
|
/// Set the volume of the player.
|
||||||
async fn set_volume(&self, input_volume: f64, option: NumberChangeOptions)
|
async fn set_volume(
|
||||||
-> Result<(), MpvError>;
|
&self,
|
||||||
|
input_volume: f64,
|
||||||
|
option: NumberChangeOptions,
|
||||||
|
) -> Result<(), MpvError>;
|
||||||
|
|
||||||
/// Set the playback speed of the player.
|
/// 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.
|
/// Toggle/set the pause state of the player.
|
||||||
async fn set_playback(&self, option: Switch) -> Result<(), MpvError>;
|
async fn set_playback(&self, option: Switch) -> Result<(), MpvError>;
|
||||||
|
@ -306,7 +313,11 @@ impl MpvExt for Mpv {
|
||||||
self.set_property("mute", enabled).await
|
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 {
|
match self.get_property::<f64>("speed").await {
|
||||||
Ok(speed) => match option {
|
Ok(speed) => match option {
|
||||||
NumberChangeOptions::Increase => {
|
NumberChangeOptions::Increase => {
|
||||||
|
|
|
@ -56,7 +56,7 @@ impl MpvIpc {
|
||||||
) -> Result<Option<Value>, MpvError> {
|
) -> Result<Option<Value>, MpvError> {
|
||||||
let ipc_command = json!({ "command": command });
|
let ipc_command = json!({ "command": command });
|
||||||
let ipc_command_str =
|
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);
|
log::trace!("Sending command: {}", ipc_command_str);
|
||||||
|
|
||||||
|
@ -75,8 +75,8 @@ impl MpvIpc {
|
||||||
))?
|
))?
|
||||||
.map_err(|why| MpvError::MpvSocketConnectionError(why.to_string()))?;
|
.map_err(|why| MpvError::MpvSocketConnectionError(why.to_string()))?;
|
||||||
|
|
||||||
let parsed_response = serde_json::from_str::<Value>(&response)
|
let parsed_response =
|
||||||
.map_err(|why| MpvError::JsonParseError(why));
|
serde_json::from_str::<Value>(&response).map_err(MpvError::JsonParseError);
|
||||||
|
|
||||||
if parsed_response
|
if parsed_response
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
@ -155,7 +155,7 @@ impl MpvIpc {
|
||||||
.map_err(|why| MpvError::MpvSocketConnectionError(why.to_string()))
|
.map_err(|why| MpvError::MpvSocketConnectionError(why.to_string()))
|
||||||
.and_then(|event|
|
.and_then(|event|
|
||||||
serde_json::from_str::<Value>(&event)
|
serde_json::from_str::<Value>(&event)
|
||||||
.map_err(|why| MpvError::JsonParseError(why)));
|
.map_err(MpvError::JsonParseError));
|
||||||
|
|
||||||
self.handle_event(parsed_event).await;
|
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> {
|
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> {
|
pub(crate) fn json_array_to_playlist(array: &[Value]) -> Vec<PlaylistEntry> {
|
||||||
|
|
|
@ -5,4 +5,4 @@
|
||||||
// mod misc;
|
// mod misc;
|
||||||
mod integration_tests;
|
mod integration_tests;
|
||||||
|
|
||||||
// use util::*;
|
// use util::*;
|
||||||
|
|
|
@ -23,4 +23,4 @@ async fn test_set_property() {
|
||||||
|
|
||||||
mpv.kill().await.unwrap();
|
mpv.kill().await.unwrap();
|
||||||
proc.kill().await.unwrap();
|
proc.kill().await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
mod event_property_parser;
|
mod event_property_parser;
|
||||||
mod util;
|
|
||||||
mod misc;
|
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 std::{panic, time::Duration};
|
||||||
|
|
||||||
use futures::{stream::FuturesUnordered, SinkExt, StreamExt};
|
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 serde_json::{json, Value};
|
||||||
use test_log::test;
|
use test_log::test;
|
||||||
use tokio::{net::UnixStream, task::JoinHandle};
|
use tokio::{net::UnixStream, task::JoinHandle};
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
mod events;
|
mod events;
|
||||||
mod get_property;
|
mod get_property;
|
||||||
mod set_property;
|
mod set_property;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::{panic, time::Duration};
|
use std::{panic, time::Duration};
|
||||||
|
|
||||||
use futures::{stream::FuturesUnordered, SinkExt, StreamExt};
|
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 serde_json::{json, Value};
|
||||||
use test_log::test;
|
use test_log::test;
|
||||||
use tokio::{net::UnixStream, task::JoinHandle};
|
use tokio::{net::UnixStream, task::JoinHandle};
|
||||||
|
@ -130,7 +130,7 @@ async fn test_set_property_simultaneous_requests() {
|
||||||
loop {
|
loop {
|
||||||
let status = mpv_clone_1.set_property("volume", 100).await;
|
let status = mpv_clone_1.set_property("volume", 100).await;
|
||||||
match status {
|
match status {
|
||||||
Ok(()) => {},
|
Ok(()) => {}
|
||||||
_ => panic!("Unexpected result: {:?}", status),
|
_ => panic!("Unexpected result: {:?}", status),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,7 @@ async fn test_set_property_simultaneous_requests() {
|
||||||
tokio::time::sleep(Duration::from_millis(1)).await;
|
tokio::time::sleep(Duration::from_millis(1)).await;
|
||||||
let status = mpv_clone_2.set_property("pause", false).await;
|
let status = mpv_clone_2.set_property("pause", false).await;
|
||||||
match status {
|
match status {
|
||||||
Ok(()) => {},
|
Ok(()) => {}
|
||||||
_ => panic!("Unexpected result: {:?}", status),
|
_ => panic!("Unexpected result: {:?}", status),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue