Remove unstable options from rustfmt.toml
This commit is contained in:
parent
6bf85ca664
commit
bc44cc23ae
|
@ -1,8 +1,4 @@
|
||||||
newline_style = "Unix"
|
newline_style = "Unix"
|
||||||
max_width = 140
|
max_width = 140
|
||||||
tab_spaces = 2
|
tab_spaces = 2
|
||||||
imports_layout = "Horizontal"
|
|
||||||
merge_imports = true
|
|
||||||
struct_field_align_threshold = 25
|
|
||||||
where_single_line = true
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
30
src/error.rs
30
src/error.rs
|
@ -5,33 +5,31 @@ pub type MpdResult<T> = std::result::Result<T, Error>;
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub struct Error {
|
pub struct Error {
|
||||||
pub message: String,
|
pub message: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error {
|
impl Error {
|
||||||
pub fn from_str(message: &str) -> Self {
|
pub fn from_str(message: &str) -> Self {
|
||||||
Error {
|
Error {
|
||||||
message: message.to_string(),
|
message: message.to_string(),
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl de::Error for Error {
|
impl de::Error for Error {
|
||||||
fn custom<T: Display>(msg: T) -> Self {
|
fn custom<T: Display>(msg: T) -> Self {
|
||||||
Error {
|
Error { message: msg.to_string() }
|
||||||
message: msg.to_string(),
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for Error {
|
impl Display for Error {
|
||||||
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
formatter.write_str(&self.message)
|
formatter.write_str(&self.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::error::Error for Error {
|
impl std::error::Error for Error {
|
||||||
fn description(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
&self.message
|
&self.message
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
132
src/structs.rs
132
src/structs.rs
|
@ -7,44 +7,44 @@ use std::{fmt, time::Duration};
|
||||||
#[derive(Deserialize, Clone, Debug, Default, PartialEq)]
|
#[derive(Deserialize, Clone, Debug, Default, PartialEq)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct Track {
|
pub struct Track {
|
||||||
pub file: String,
|
pub file: String,
|
||||||
#[serde(rename = "artistsort")]
|
#[serde(rename = "artistsort")]
|
||||||
pub artist_sort: Option<String>,
|
pub artist_sort: Option<String>,
|
||||||
#[serde(rename = "albumartist")]
|
#[serde(rename = "albumartist")]
|
||||||
pub album_artist: Option<String>,
|
pub album_artist: Option<String>,
|
||||||
#[serde(rename = "albumsort")]
|
#[serde(rename = "albumsort")]
|
||||||
pub album_sort: Option<String>,
|
pub album_sort: Option<String>,
|
||||||
#[serde(rename = "albumartistsort")]
|
#[serde(rename = "albumartistsort")]
|
||||||
pub album_artist_sort: Option<String>,
|
pub album_artist_sort: Option<String>,
|
||||||
#[serde(deserialize_with = "de_string_or_vec")]
|
#[serde(deserialize_with = "de_string_or_vec")]
|
||||||
#[serde(rename = "performer")]
|
#[serde(rename = "performer")]
|
||||||
pub performers: Vec<String>,
|
pub performers: Vec<String>,
|
||||||
pub genre: Option<String>,
|
pub genre: Option<String>,
|
||||||
pub title: Option<String>,
|
pub title: Option<String>,
|
||||||
#[serde(deserialize_with = "de_position")]
|
#[serde(deserialize_with = "de_position")]
|
||||||
pub track: Option<Position>,
|
pub track: Option<Position>,
|
||||||
pub album: Option<String>,
|
pub album: Option<String>,
|
||||||
pub artist: Option<String>,
|
pub artist: Option<String>,
|
||||||
pub pos: u32,
|
pub pos: u32,
|
||||||
pub id: u32,
|
pub id: u32,
|
||||||
#[serde(rename = "last-modified")]
|
#[serde(rename = "last-modified")]
|
||||||
pub last_modified: Option<DateTime<FixedOffset>>,
|
pub last_modified: Option<DateTime<FixedOffset>>,
|
||||||
#[serde(rename = "originaldate")]
|
#[serde(rename = "originaldate")]
|
||||||
pub original_date: Option<u16>,
|
pub original_date: Option<u16>,
|
||||||
pub format: Option<String>,
|
pub format: Option<String>,
|
||||||
#[serde(deserialize_with = "de_time_float")]
|
#[serde(deserialize_with = "de_time_float")]
|
||||||
pub duration: Option<Duration>,
|
pub duration: Option<Duration>,
|
||||||
pub label: Option<String>,
|
pub label: Option<String>,
|
||||||
pub date: Option<u16>,
|
pub date: Option<u16>,
|
||||||
#[serde(deserialize_with = "de_position")]
|
#[serde(deserialize_with = "de_position")]
|
||||||
pub disc: Option<Position>,
|
pub disc: Option<Position>,
|
||||||
pub musicbraiz_trackid: Option<String>,
|
pub musicbraiz_trackid: Option<String>,
|
||||||
pub musicbrainz_albumid: Option<String>,
|
pub musicbrainz_albumid: Option<String>,
|
||||||
pub musicbrainz_albumartistid: Option<String>,
|
pub musicbrainz_albumartistid: Option<String>,
|
||||||
pub musicbrainz_artistid: Option<String>,
|
pub musicbrainz_artistid: Option<String>,
|
||||||
pub musicbrainz_releasetrackid: Option<String>,
|
pub musicbrainz_releasetrackid: Option<String>,
|
||||||
pub musicbrainz_trackid: Option<String>,
|
pub musicbrainz_trackid: Option<String>,
|
||||||
pub composer: Option<String>,
|
pub composer: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An empty struct that can be used as the response data for commands that only ever return `OK`
|
/// An empty struct that can be used as the response data for commands that only ever return `OK`
|
||||||
|
@ -59,7 +59,7 @@ pub struct UnitResponse {}
|
||||||
#[derive(Deserialize, Clone, Debug, Default, PartialEq)]
|
#[derive(Deserialize, Clone, Debug, Default, PartialEq)]
|
||||||
pub struct Position {
|
pub struct Position {
|
||||||
pub item_position: u16,
|
pub item_position: u16,
|
||||||
pub total_items: Option<u16>,
|
pub total_items: Option<u16>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Position {
|
impl fmt::Display for Position {
|
||||||
|
@ -81,40 +81,40 @@ impl fmt::Display for Position {
|
||||||
#[derive(Deserialize, Clone, Debug, Default, PartialEq)]
|
#[derive(Deserialize, Clone, Debug, Default, PartialEq)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct Status {
|
pub struct Status {
|
||||||
pub volume: Option<u8>,
|
pub volume: Option<u8>,
|
||||||
#[serde(deserialize_with = "de_bint")]
|
#[serde(deserialize_with = "de_bint")]
|
||||||
pub repeat: bool,
|
pub repeat: bool,
|
||||||
#[serde(deserialize_with = "de_bint")]
|
#[serde(deserialize_with = "de_bint")]
|
||||||
pub random: bool,
|
pub random: bool,
|
||||||
// TODO: make enum
|
// TODO: make enum
|
||||||
pub single: u8,
|
pub single: u8,
|
||||||
#[serde(deserialize_with = "de_bint")]
|
#[serde(deserialize_with = "de_bint")]
|
||||||
pub consume: bool,
|
pub consume: bool,
|
||||||
// an empty playlist still has an ID
|
// an empty playlist still has an ID
|
||||||
pub playlist: u32,
|
pub playlist: u32,
|
||||||
// mpd returns 0 if there is no current playlist
|
// mpd returns 0 if there is no current playlist
|
||||||
pub playlistlength: u32,
|
pub playlistlength: u32,
|
||||||
#[serde(deserialize_with = "de_state")]
|
#[serde(deserialize_with = "de_state")]
|
||||||
pub state: State,
|
pub state: State,
|
||||||
pub song: Option<u32>,
|
pub song: Option<u32>,
|
||||||
pub songid: Option<u32>,
|
pub songid: Option<u32>,
|
||||||
pub nextsong: Option<u32>,
|
pub nextsong: Option<u32>,
|
||||||
pub nextsongid: Option<u32>,
|
pub nextsongid: Option<u32>,
|
||||||
#[serde(deserialize_with = "de_time_float")]
|
#[serde(deserialize_with = "de_time_float")]
|
||||||
pub elapsed: Option<Duration>,
|
pub elapsed: Option<Duration>,
|
||||||
#[serde(deserialize_with = "de_time_float")]
|
#[serde(deserialize_with = "de_time_float")]
|
||||||
pub duration: Option<Duration>,
|
pub duration: Option<Duration>,
|
||||||
pub bitrate: Option<u16>,
|
pub bitrate: Option<u16>,
|
||||||
pub xfade: Option<u8>,
|
pub xfade: Option<u8>,
|
||||||
// 0 if unset
|
// 0 if unset
|
||||||
pub mixrampdb: f32,
|
pub mixrampdb: f32,
|
||||||
pub mixrampdelay: Option<u8>,
|
pub mixrampdelay: Option<u8>,
|
||||||
// “audio: The format emitted by the decoder plugin during playback, format: samplerate:bits:channels.
|
// “audio: The format emitted by the decoder plugin during playback, format: samplerate:bits:channels.
|
||||||
// See Global Audio Format for a detailed explanation.”
|
// See Global Audio Format for a detailed explanation.”
|
||||||
// TODO: make struct
|
// TODO: make struct
|
||||||
pub audio: Option<String>,
|
pub audio: Option<String>,
|
||||||
pub updating_db: Option<u32>,
|
pub updating_db: Option<u32>,
|
||||||
pub error: Option<String>,
|
pub error: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Clone, Debug, PartialEq)]
|
#[derive(Deserialize, Clone, Debug, PartialEq)]
|
||||||
|
@ -135,17 +135,17 @@ impl Default for State {
|
||||||
#[derive(Deserialize, Clone, Debug, Default, PartialEq)]
|
#[derive(Deserialize, Clone, Debug, Default, PartialEq)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct Stats {
|
pub struct Stats {
|
||||||
pub artists: u32,
|
pub artists: u32,
|
||||||
pub albums: u32,
|
pub albums: u32,
|
||||||
pub songs: u32,
|
pub songs: u32,
|
||||||
#[serde(deserialize_with = "de_time_int")]
|
#[serde(deserialize_with = "de_time_int")]
|
||||||
pub uptime: Duration,
|
pub uptime: Duration,
|
||||||
#[serde(deserialize_with = "de_time_int")]
|
#[serde(deserialize_with = "de_time_int")]
|
||||||
pub db_playtime: Duration,
|
pub db_playtime: Duration,
|
||||||
// TODO: this is a unix era. use some datetime for it
|
// TODO: this is a unix era. use some datetime for it
|
||||||
pub db_update: u32,
|
pub db_update: u32,
|
||||||
#[serde(deserialize_with = "de_time_int")]
|
#[serde(deserialize_with = "de_time_int")]
|
||||||
pub playtime: Duration,
|
pub playtime: Duration,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Deserialization helpers to handle the quirks of mpd’s output.
|
/// Deserialization helpers to handle the quirks of mpd’s output.
|
||||||
|
@ -158,20 +158,26 @@ mod helpers {
|
||||||
/// Deserialize time from an integer that represents the seconds.
|
/// Deserialize time from an integer that represents the seconds.
|
||||||
/// mpd uses int for the database stats (e.g. total time played).
|
/// mpd uses int for the database stats (e.g. total time played).
|
||||||
pub fn de_time_int<'de, D>(deserializer: D) -> Result<Duration, D::Error>
|
pub fn de_time_int<'de, D>(deserializer: D) -> Result<Duration, D::Error>
|
||||||
where D: de::Deserializer<'de> {
|
where
|
||||||
|
D: de::Deserializer<'de>,
|
||||||
|
{
|
||||||
u64::deserialize(deserializer).map(Duration::from_secs)
|
u64::deserialize(deserializer).map(Duration::from_secs)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Deserialize time from a float that represents the seconds.
|
/// Deserialize time from a float that represents the seconds.
|
||||||
/// mpd uses floats for the current status (e.g. time elapsed in song).
|
/// mpd uses floats for the current status (e.g. time elapsed in song).
|
||||||
pub fn de_time_float<'de, D>(deserializer: D) -> Result<Option<Duration>, D::Error>
|
pub fn de_time_float<'de, D>(deserializer: D) -> Result<Option<Duration>, D::Error>
|
||||||
where D: de::Deserializer<'de> {
|
where
|
||||||
|
D: de::Deserializer<'de>,
|
||||||
|
{
|
||||||
f64::deserialize(deserializer).map(Duration::from_secs_f64).map(Some)
|
f64::deserialize(deserializer).map(Duration::from_secs_f64).map(Some)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Deserialize the playback state.
|
/// Deserialize the playback state.
|
||||||
pub fn de_state<'de, D>(deserializer: D) -> Result<State, D::Error>
|
pub fn de_state<'de, D>(deserializer: D) -> Result<State, D::Error>
|
||||||
where D: de::Deserializer<'de> {
|
where
|
||||||
|
D: de::Deserializer<'de>,
|
||||||
|
{
|
||||||
match String::deserialize(deserializer)?.as_ref() {
|
match String::deserialize(deserializer)?.as_ref() {
|
||||||
"play" => Ok(State::Play),
|
"play" => Ok(State::Play),
|
||||||
"pause" => Ok(State::Pause),
|
"pause" => Ok(State::Pause),
|
||||||
|
@ -184,14 +190,18 @@ mod helpers {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn de_string_or_vec<'de, D>(deserializer: D) -> Result<Vec<String>, D::Error>
|
pub fn de_string_or_vec<'de, D>(deserializer: D) -> Result<Vec<String>, D::Error>
|
||||||
where D: de::Deserializer<'de> {
|
where
|
||||||
|
D: de::Deserializer<'de>,
|
||||||
|
{
|
||||||
String::deserialize(deserializer).map(|s| s.split(SEPARATOR).map(std::string::String::from).collect())
|
String::deserialize(deserializer).map(|s| s.split(SEPARATOR).map(std::string::String::from).collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// mpd uses bints (0 or 1) to represent booleans,
|
/// mpd uses bints (0 or 1) to represent booleans,
|
||||||
/// so we need a special parser for those.
|
/// so we need a special parser for those.
|
||||||
pub fn de_bint<'de, D>(deserializer: D) -> Result<bool, D::Error>
|
pub fn de_bint<'de, D>(deserializer: D) -> Result<bool, D::Error>
|
||||||
where D: de::Deserializer<'de> {
|
where
|
||||||
|
D: de::Deserializer<'de>,
|
||||||
|
{
|
||||||
match u8::deserialize(deserializer)? {
|
match u8::deserialize(deserializer)? {
|
||||||
0 => Ok(false),
|
0 => Ok(false),
|
||||||
1 => Ok(true),
|
1 => Ok(true),
|
||||||
|
@ -202,13 +212,15 @@ mod helpers {
|
||||||
/// Deserialize a position with an optional total length.
|
/// Deserialize a position with an optional total length.
|
||||||
/// The input string here is either a number or two numbers separated by `SEPARATOR`.
|
/// The input string here is either a number or two numbers separated by `SEPARATOR`.
|
||||||
pub fn de_position<'de, D>(deserializer: D) -> Result<Option<Position>, D::Error>
|
pub fn de_position<'de, D>(deserializer: D) -> Result<Option<Position>, D::Error>
|
||||||
where D: de::Deserializer<'de> {
|
where
|
||||||
|
D: de::Deserializer<'de>,
|
||||||
|
{
|
||||||
let s = String::deserialize(deserializer)?;
|
let s = String::deserialize(deserializer)?;
|
||||||
let mut ints = s.split(SEPARATOR).filter_map(|s| u16::from_str(s).ok());
|
let mut ints = s.split(SEPARATOR).filter_map(|s| u16::from_str(s).ok());
|
||||||
if let Some(n) = ints.next() {
|
if let Some(n) = ints.next() {
|
||||||
return Ok(Some(Position {
|
return Ok(Some(Position {
|
||||||
item_position: n,
|
item_position: n,
|
||||||
total_items: ints.next(),
|
total_items: ints.next(),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
Ok(None)
|
Ok(None)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user