Change rust edition from 2021 -> 2024
Some checks failed
Build and test / build (push) Successful in 54s
Build and test / check (push) Successful in 55s
Build and test / docs (push) Successful in 1m24s
Build and test / test (push) Failing after 2m9s

This commit is contained in:
2025-12-15 09:52:24 +09:00
parent 6224d94008
commit c4b77dd198
14 changed files with 53 additions and 48 deletions

View File

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

View File

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

1
rustfmt.toml Normal file
View File

@@ -0,0 +1 @@
style_edition = "2024"

View File

@@ -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<Option<Self>, MpvError>;
-> Result<Option<Self>, MpvError>;
}
impl<T> GetPropertyTypeHandler for T
@@ -185,7 +185,7 @@ pub trait SetPropertyTypeHandler<T> {
// TODO: fix this
#[allow(async_fn_in_trait)]
async fn set_property_generic(instance: &Mpv, property: &str, value: T)
-> Result<(), MpvError>;
-> Result<(), MpvError>;
}
impl<T> SetPropertyTypeHandler<T> for T

View File

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

View File

@@ -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")]

View File

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

View File

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

View File

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

View File

@@ -68,7 +68,7 @@ pub fn parse_property(name: &str, data: Option<MpvDataType>) -> Result<Property,
return Err(MpvError::DataContainsUnexpectedType {
expected_type: "String".to_owned(),
received: data,
})
});
}
None => {
return Err(MpvError::MissingMpvData);
@@ -83,7 +83,7 @@ pub fn parse_property(name: &str, data: Option<MpvDataType>) -> Result<Property,
return Err(MpvError::DataContainsUnexpectedType {
expected_type: "bool".to_owned(),
received: data,
})
});
}
None => {
return Err(MpvError::MissingMpvData);
@@ -99,7 +99,7 @@ pub fn parse_property(name: &str, data: Option<MpvDataType>) -> Result<Property,
return Err(MpvError::DataContainsUnexpectedType {
expected_type: "f64".to_owned(),
received: data,
})
});
}
};
Ok(Property::PlaybackTime(playback_time))
@@ -112,7 +112,7 @@ pub fn parse_property(name: &str, data: Option<MpvDataType>) -> Result<Property,
return Err(MpvError::DataContainsUnexpectedType {
expected_type: "f64".to_owned(),
received: data,
})
});
}
};
Ok(Property::Duration(duration))
@@ -125,7 +125,7 @@ pub fn parse_property(name: &str, data: Option<MpvDataType>) -> Result<Property,
return Err(MpvError::DataContainsUnexpectedType {
expected_type: "HashMap".to_owned(),
received: data,
})
});
}
};
Ok(Property::Metadata(metadata))
@@ -138,7 +138,7 @@ pub fn parse_property(name: &str, data: Option<MpvDataType>) -> Result<Property,
return Err(MpvError::DataContainsUnexpectedType {
expected_type: "Array".to_owned(),
received: data,
})
});
}
};
Ok(Property::Playlist(playlist))
@@ -153,7 +153,7 @@ pub fn parse_property(name: &str, data: Option<MpvDataType>) -> Result<Property,
return Err(MpvError::DataContainsUnexpectedType {
expected_type: "usize or -1".to_owned(),
received: data,
})
});
}
};
Ok(Property::PlaylistPos(playlist_pos))
@@ -210,7 +210,7 @@ pub fn parse_property(name: &str, data: Option<MpvDataType>) -> Result<Property,
return Err(MpvError::DataContainsUnexpectedType {
expected_type: "f64".to_owned(),
received: data,
})
});
}
None => None,
};
@@ -224,7 +224,7 @@ pub fn parse_property(name: &str, data: Option<MpvDataType>) -> Result<Property,
return Err(MpvError::DataContainsUnexpectedType {
expected_type: "f64".to_owned(),
received: data,
})
});
}
None => None,
};
@@ -237,7 +237,7 @@ pub fn parse_property(name: &str, data: Option<MpvDataType>) -> Result<Property,
return Err(MpvError::DataContainsUnexpectedType {
expected_type: "f64".to_owned(),
received: data,
})
});
}
None => {
return Err(MpvError::MissingMpvData);
@@ -252,7 +252,7 @@ pub fn parse_property(name: &str, data: Option<MpvDataType>) -> Result<Property,
return Err(MpvError::DataContainsUnexpectedType {
expected_type: "f64".to_owned(),
received: data,
})
});
}
None => {
return Err(MpvError::MissingMpvData);
@@ -267,7 +267,7 @@ pub fn parse_property(name: &str, data: Option<MpvDataType>) -> Result<Property,
return Err(MpvError::DataContainsUnexpectedType {
expected_type: "bool".to_owned(),
received: data,
})
});
}
None => {
return Err(MpvError::MissingMpvData);
@@ -282,7 +282,7 @@ pub fn parse_property(name: &str, data: Option<MpvDataType>) -> Result<Property,
return Err(MpvError::DataContainsUnexpectedType {
expected_type: "bool".to_owned(),
received: data,
})
});
}
None => 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,
};

View File

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

View File

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

View File

@@ -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::<Vec<Value>>(),
"request_id": 0,
"error": "success"
})
}).collect::<Vec<Value>>(),
"request_id": 0,
"error": "success"
})
.to_string()]);
.to_string(),
]);
let mpv = Mpv::connect_socket(server).await?;
let playlist = mpv.get_playlist().await?;

View File

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