diff --git a/Cargo.toml b/Cargo.toml index 0d2e13f..f86ac74 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,8 +9,8 @@ description = "A small library which provides bindings to control existing mpv i license = "GPL-3.0" repository = "https://git.pvv.ntnu.no/Grzegorz/mpvipc-async" documentation = "https://pages.pvv.ntnu.no/Grzegorz/mpvipc-async/main/docs/mpvipc_async/" -edition = "2021" -rust-version = "1.75" +edition = "2024" +rust-version = "1.85.0" [dependencies] serde_json = "1.0.145" diff --git a/examples/media_player.rs b/examples/media_player.rs index afe8e63..243db9f 100644 --- a/examples/media_player.rs +++ b/examples/media_player.rs @@ -1,5 +1,5 @@ use futures::StreamExt; -use mpvipc_async::{parse_property, Event, Mpv, MpvDataType, MpvError, MpvExt, Property}; +use mpvipc_async::{Event, Mpv, MpvDataType, MpvError, MpvExt, Property, parse_property}; fn seconds_to_hms(total: f64) -> String { let total = total as u64; diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..3501136 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1 @@ +style_edition = "2024" diff --git a/src/core_api.rs b/src/core_api.rs index 87e3338..80f3fd3 100644 --- a/src/core_api.rs +++ b/src/core_api.rs @@ -10,9 +10,9 @@ use tokio::{ }; use crate::{ + Event, MpvError, ipc::{MpvIpc, MpvIpcCommand, MpvIpcEvent, MpvIpcResponse}, message_parser::TypeHandler, - Event, MpvError, }; /// All possible commands that can be sent to mpv. @@ -162,7 +162,7 @@ pub trait GetPropertyTypeHandler: Sized { // TODO: fix this #[allow(async_fn_in_trait)] async fn get_property_generic(instance: &Mpv, property: &str) - -> Result, MpvError>; + -> Result, MpvError>; } impl GetPropertyTypeHandler for T @@ -185,7 +185,7 @@ pub trait SetPropertyTypeHandler { // TODO: fix this #[allow(async_fn_in_trait)] async fn set_property_generic(instance: &Mpv, property: &str, value: T) - -> Result<(), MpvError>; + -> Result<(), MpvError>; } impl SetPropertyTypeHandler for T diff --git a/src/error.rs b/src/error.rs index 16cfeba..f18be50 100644 --- a/src/error.rs +++ b/src/error.rs @@ -23,7 +23,9 @@ pub enum MpvError { #[error("JsonParseError: {0}")] JsonParseError(#[from] serde_json::Error), - #[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 { expected_type: String, received: Value, diff --git a/src/event_parser.rs b/src/event_parser.rs index 24ad225..d906d60 100644 --- a/src/event_parser.rs +++ b/src/event_parser.rs @@ -5,7 +5,7 @@ use std::str::FromStr; use serde::{Deserialize, Serialize}; use serde_json::{Map, Value}; -use crate::{ipc::MpvIpcEvent, message_parser::json_to_value, MpvDataType, MpvError}; +use crate::{MpvDataType, MpvError, ipc::MpvIpcEvent, message_parser::json_to_value}; #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "kebab-case")] diff --git a/src/highlevel_api_extension.rs b/src/highlevel_api_extension.rs index 98a318c..c2f3544 100644 --- a/src/highlevel_api_extension.rs +++ b/src/highlevel_api_extension.rs @@ -1,8 +1,8 @@ //! High-level API extension for [`Mpv`]. use crate::{ - parse_property, IntoRawCommandPart, LoopProperty, Mpv, MpvCommand, MpvDataType, MpvError, - Playlist, PlaylistAddOptions, Property, SeekOptions, + IntoRawCommandPart, LoopProperty, Mpv, MpvCommand, MpvDataType, MpvError, Playlist, + PlaylistAddOptions, Property, SeekOptions, parse_property, }; use serde::{Deserialize, Serialize}; use std::collections::HashMap; diff --git a/src/ipc.rs b/src/ipc.rs index 60d5b4c..7cc323d 100644 --- a/src/ipc.rs +++ b/src/ipc.rs @@ -1,7 +1,7 @@ //! IPC handling thread/task. Handles communication between [`Mpv`](crate::Mpv) instances and mpv's unix socket use futures::{SinkExt, StreamExt}; -use serde_json::{json, Value}; +use serde_json::{Value, json}; use tokio::{ net::UnixStream, sync::{broadcast, mpsc, oneshot}, diff --git a/src/message_parser.rs b/src/message_parser.rs index 25febe5..d906bc4 100644 --- a/src/message_parser.rs +++ b/src/message_parser.rs @@ -164,7 +164,7 @@ fn json_map_to_playlist_entry( return Err(MpvError::ValueContainsUnexpectedType { expected_type: "String".to_owned(), received: data.clone(), - }) + }); } None => return Err(MpvError::MissingMpvData), }; @@ -174,7 +174,7 @@ fn json_map_to_playlist_entry( return Err(MpvError::ValueContainsUnexpectedType { expected_type: "String".to_owned(), received: data.clone(), - }) + }); } None => None, }; @@ -184,7 +184,7 @@ fn json_map_to_playlist_entry( return Err(MpvError::ValueContainsUnexpectedType { expected_type: "bool".to_owned(), received: data.clone(), - }) + }); } None => false, }; diff --git a/src/property_parser.rs b/src/property_parser.rs index 6cb3776..1b04c4c 100644 --- a/src/property_parser.rs +++ b/src/property_parser.rs @@ -68,7 +68,7 @@ pub fn parse_property(name: &str, data: Option) -> Result { return Err(MpvError::MissingMpvData); @@ -83,7 +83,7 @@ pub fn parse_property(name: &str, data: Option) -> Result { return Err(MpvError::MissingMpvData); @@ -99,7 +99,7 @@ pub fn parse_property(name: &str, data: Option) -> Result) -> Result) -> Result) -> Result) -> Result) -> Result None, }; @@ -224,7 +224,7 @@ pub fn parse_property(name: &str, data: Option) -> Result None, }; @@ -237,7 +237,7 @@ pub fn parse_property(name: &str, data: Option) -> Result { return Err(MpvError::MissingMpvData); @@ -252,7 +252,7 @@ pub fn parse_property(name: &str, data: Option) -> Result { return Err(MpvError::MissingMpvData); @@ -267,7 +267,7 @@ pub fn parse_property(name: &str, data: Option) -> Result { return Err(MpvError::MissingMpvData); @@ -282,7 +282,7 @@ pub fn parse_property(name: &str, data: Option) -> Result true, }; @@ -305,7 +305,7 @@ fn mpv_data_to_playlist_entry( return Err(MpvError::DataContainsUnexpectedType { expected_type: "String".to_owned(), received: data.clone(), - }) + }); } None => return Err(MpvError::MissingMpvData), }; @@ -315,7 +315,7 @@ fn mpv_data_to_playlist_entry( return Err(MpvError::DataContainsUnexpectedType { expected_type: "String".to_owned(), received: data.clone(), - }) + }); } None => None, }; @@ -325,7 +325,7 @@ fn mpv_data_to_playlist_entry( return Err(MpvError::DataContainsUnexpectedType { expected_type: "bool".to_owned(), received: data.clone(), - }) + }); } None => false, }; diff --git a/tests/integration_tests/event_property_parser.rs b/tests/integration_tests/event_property_parser.rs index 84b2dbe..165ecc3 100644 --- a/tests/integration_tests/event_property_parser.rs +++ b/tests/integration_tests/event_property_parser.rs @@ -1,8 +1,8 @@ -use futures::{stream::StreamExt, Stream}; -use mpvipc_async::{parse_property, Event, Mpv, MpvError, MpvExt, Property}; +use futures::{Stream, stream::StreamExt}; +use mpvipc_async::{Event, Mpv, MpvError, MpvExt, Property, parse_property}; use thiserror::Error; use tokio::time::sleep; -use tokio::time::{timeout, Duration}; +use tokio::time::{Duration, timeout}; use test_log::test; diff --git a/tests/mock_socket_tests/events.rs b/tests/mock_socket_tests/events.rs index bc0481d..8d53b39 100644 --- a/tests/mock_socket_tests/events.rs +++ b/tests/mock_socket_tests/events.rs @@ -1,4 +1,4 @@ -use futures::{stream::StreamExt, SinkExt}; +use futures::{SinkExt, stream::StreamExt}; use mpvipc_async::{Event, Mpv, MpvDataType, MpvExt}; use serde_json::json; use test_log::test; diff --git a/tests/mock_socket_tests/get_property.rs b/tests/mock_socket_tests/get_property.rs index 4b730ce..a93298a 100644 --- a/tests/mock_socket_tests/get_property.rs +++ b/tests/mock_socket_tests/get_property.rs @@ -1,8 +1,8 @@ use std::{panic, time::Duration}; -use futures::{stream::FuturesUnordered, SinkExt, StreamExt}; +use futures::{SinkExt, StreamExt, stream::FuturesUnordered}; use mpvipc_async::{Mpv, MpvError, MpvExt, Playlist, PlaylistEntry}; -use serde_json::{json, Value}; +use serde_json::{Value, json}; use test_log::test; use tokio::{net::UnixStream, task::JoinHandle}; use tokio_util::codec::{Framed, LinesCodec, LinesCodecError}; @@ -196,18 +196,20 @@ async fn test_get_playlist() -> Result<(), MpvError> { }, ]); - let (server, join_handle) = test_socket(vec![json!({ - "data": expected.0.iter().map(|entry| { + let (server, join_handle) = test_socket(vec![ json!({ - "filename": entry.filename, - "title": entry.title, - "current": entry.current + "data": expected.0.iter().map(|entry| { + json!({ + "filename": entry.filename, + "title": entry.title, + "current": entry.current + }) + }).collect::>(), + "request_id": 0, + "error": "success" }) - }).collect::>(), - "request_id": 0, - "error": "success" - }) - .to_string()]); + .to_string(), + ]); let mpv = Mpv::connect_socket(server).await?; let playlist = mpv.get_playlist().await?; diff --git a/tests/mock_socket_tests/set_property.rs b/tests/mock_socket_tests/set_property.rs index 99e9b8a..d8846d8 100644 --- a/tests/mock_socket_tests/set_property.rs +++ b/tests/mock_socket_tests/set_property.rs @@ -1,8 +1,8 @@ use std::{panic, time::Duration}; -use futures::{stream::FuturesUnordered, SinkExt, StreamExt}; +use futures::{SinkExt, StreamExt, stream::FuturesUnordered}; use mpvipc_async::{Mpv, MpvError}; -use serde_json::{json, Value}; +use serde_json::{Value, json}; use test_log::test; use tokio::{net::UnixStream, task::JoinHandle}; use tokio_util::codec::{Framed, LinesCodec, LinesCodecError};