diff --git a/src/common/types/absolute_relative_song_position.rs b/src/common/types/absolute_relative_song_position.rs index 7865a345..416d5e24 100644 --- a/src/common/types/absolute_relative_song_position.rs +++ b/src/common/types/absolute_relative_song_position.rs @@ -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), + } + } +} diff --git a/src/common/types/audio.rs b/src/common/types/audio.rs index 2672b49f..ff8ba1a0 100644 --- a/src/common/types/audio.rs +++ b/src/common/types/audio.rs @@ -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 + ) + } +} diff --git a/src/common/types/bool_or_oneshot.rs b/src/common/types/bool_or_oneshot.rs index 3960b628..131c76a1 100644 --- a/src/common/types/bool_or_oneshot.rs +++ b/src/common/types/bool_or_oneshot.rs @@ -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"), + } + } +} diff --git a/src/common/types/group_type.rs b/src/common/types/group_type.rs index 2d2c0562..756ff66c 100644 --- a/src/common/types/group_type.rs +++ b/src/common/types/group_type.rs @@ -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) + } +} diff --git a/src/common/types/one_or_range.rs b/src/common/types/one_or_range.rs index 8a7a0bd4..7b2d4614 100644 --- a/src/common/types/one_or_range.rs +++ b/src/common/types/one_or_range.rs @@ -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), + } + } +} diff --git a/src/common/types/replay_gain_mode_mode.rs b/src/common/types/replay_gain_mode_mode.rs index 597a3927..5de123ee 100644 --- a/src/common/types/replay_gain_mode_mode.rs +++ b/src/common/types/replay_gain_mode_mode.rs @@ -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) + } +} diff --git a/src/common/types/save_mode.rs b/src/common/types/save_mode.rs index 228db818..970584b3 100644 --- a/src/common/types/save_mode.rs +++ b/src/common/types/save_mode.rs @@ -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) + } +} diff --git a/src/common/types/subsystem.rs b/src/common/types/subsystem.rs index de6a720c..337cdb0a 100644 --- a/src/common/types/subsystem.rs +++ b/src/common/types/subsystem.rs @@ -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), + } + } +} diff --git a/src/common/types/time_interval.rs b/src/common/types/time_interval.rs index 416ec871..859e60ce 100644 --- a/src/common/types/time_interval.rs +++ b/src/common/types/time_interval.rs @@ -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, ":"), + } + } +} diff --git a/src/common/types/volume_value.rs b/src/common/types/volume_value.rs index 0222b535..557f6d92 100644 --- a/src/common/types/volume_value.rs +++ b/src/common/types/volume_value.rs @@ -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) + } +} diff --git a/src/common/types/window_range.rs b/src/common/types/window_range.rs index 5fddb5ed..c8ed4804 100644 --- a/src/common/types/window_range.rs +++ b/src/common/types/window_range.rs @@ -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), + } + } +}