common/types: implement fmt::Display
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use std::str::FromStr;
|
||||
use std::{fmt::Display, str::FromStr};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -22,3 +22,13 @@ impl FromStr for AbsouluteRelativeSongPosition {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for AbsouluteRelativeSongPosition {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::Absolute(pos) => write!(f, "{}", pos),
|
||||
Self::RelativePlus(pos) => write!(f, "+{}", pos),
|
||||
Self::RelativeMinus(pos) => write!(f, "-{}", pos),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::str::FromStr;
|
||||
use std::{fmt::Display, str::FromStr};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -24,3 +24,15 @@ impl FromStr for Audio {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Audio {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"{}:{:X}:{}",
|
||||
self.sample_rate,
|
||||
self.bits - 1,
|
||||
self.channels
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::str::FromStr;
|
||||
use std::{fmt, str::FromStr};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -21,3 +21,13 @@ impl FromStr for BoolOrOneshot {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for BoolOrOneshot {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
BoolOrOneshot::True => write!(f, "1"),
|
||||
BoolOrOneshot::False => write!(f, "0"),
|
||||
BoolOrOneshot::Oneshot => write!(f, "oneshot"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::str::FromStr;
|
||||
use std::{fmt::Display, str::FromStr};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -41,3 +41,24 @@ impl FromStr for GroupType {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for GroupType {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let s = match self {
|
||||
Self::Artist => "artist",
|
||||
Self::Album => "album",
|
||||
Self::AlbumArtist => "albumartist",
|
||||
Self::Date => "date",
|
||||
Self::Genre => "genre",
|
||||
Self::Track => "track",
|
||||
Self::Composer => "composer",
|
||||
Self::Performer => "performer",
|
||||
Self::Conductor => "conductor",
|
||||
Self::Comment => "comment",
|
||||
Self::Disc => "disc",
|
||||
Self::Filename => "filename",
|
||||
Self::Any => "any",
|
||||
};
|
||||
write!(f, "{}", s)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::str::FromStr;
|
||||
use std::{fmt::Display, str::FromStr};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -26,3 +26,12 @@ impl FromStr for OneOrRange {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for OneOrRange {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
OneOrRange::One(pos) => write!(f, "{}", pos),
|
||||
OneOrRange::Range(start, end) => write!(f, "{}:{}", start, end),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::str::FromStr;
|
||||
use std::{fmt::Display, str::FromStr};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -21,3 +21,15 @@ impl FromStr for ReplayGainModeMode {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for ReplayGainModeMode {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let s = match self {
|
||||
Self::Off => "off",
|
||||
Self::Track => "track",
|
||||
Self::Album => "album",
|
||||
Self::Auto => "auto",
|
||||
};
|
||||
write!(f, "{}", s)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::str::FromStr;
|
||||
use std::{fmt::Display, str::FromStr};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -19,3 +19,14 @@ impl FromStr for SaveMode {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for SaveMode {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let s = match self {
|
||||
SaveMode::Create => "create",
|
||||
SaveMode::Append => "append",
|
||||
SaveMode::Replace => "replace",
|
||||
};
|
||||
write!(f, "{}", s)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::str::FromStr;
|
||||
use std::{fmt::Display, str::FromStr};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -63,3 +63,25 @@ impl FromStr for SubSystem {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for SubSystem {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::Database => write!(f, "database"),
|
||||
Self::Update => write!(f, "update"),
|
||||
Self::StoredPlaylist => write!(f, "stored_playlist"),
|
||||
Self::Playlist => write!(f, "playlist"),
|
||||
Self::Player => write!(f, "player"),
|
||||
Self::Mixer => write!(f, "mixer"),
|
||||
Self::Output => write!(f, "output"),
|
||||
Self::Options => write!(f, "options"),
|
||||
Self::Partition => write!(f, "partition"),
|
||||
Self::Sticker => write!(f, "sticker"),
|
||||
Self::Subscription => write!(f, "subscription"),
|
||||
Self::Message => write!(f, "message"),
|
||||
Self::Neighbor => write!(f, "neighbor"),
|
||||
Self::Mount => write!(f, "mount"),
|
||||
Self::Other(other) => write!(f, "{}", other),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::str::FromStr;
|
||||
use std::{fmt::Display, str::FromStr};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -33,3 +33,14 @@ impl FromStr for TimeInterval {
|
||||
Ok(Self { start, end })
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for TimeInterval {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match (self.start.as_ref(), self.end.as_ref()) {
|
||||
(Some(start), Some(end)) => write!(f, "{}:{}", start, end),
|
||||
(Some(start), None) => write!(f, "{}:", start),
|
||||
(None, Some(end)) => write!(f, ":{}", end),
|
||||
(None, None) => write!(f, ":"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::str::FromStr;
|
||||
use std::{fmt::Display, str::FromStr};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -24,3 +24,9 @@ impl FromStr for VolumeValue {
|
||||
VolumeValue::new(volume)
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for VolumeValue {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::str::FromStr;
|
||||
use std::{fmt::Display, str::FromStr};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -26,3 +26,12 @@ impl FromStr for WindowRange {
|
||||
Ok(Self { start, end })
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for WindowRange {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self.end {
|
||||
Some(end) => write!(f, "{}:{}", self.start, end),
|
||||
None => write!(f, "{}:", self.start),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user