Skip to main content

mpris_server/
playback_status.rs

1use std::fmt;
2
3use serde::{Deserialize, Serialize};
4use zbus::zvariant::{Type, Variant};
5
6/// A playback state.
7#[derive(Deserialize, Serialize, Debug, Clone, Copy, PartialEq, Eq, Type)]
8#[zvariant(signature = "s")]
9#[doc(alias = "Playback_Status")]
10pub enum PlaybackStatus {
11    /// A track is currently playing.
12    Playing,
13    /// A track is currently paused.
14    Paused,
15    /// There is no track currently playing.
16    Stopped,
17}
18
19impl PlaybackStatus {
20    /// Returns the string representation of this playback status.
21    pub fn as_str(&self) -> &'static str {
22        match self {
23            Self::Playing => "Playing",
24            Self::Paused => "Paused",
25            Self::Stopped => "Stopped",
26        }
27    }
28}
29
30impl fmt::Display for PlaybackStatus {
31    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32        f.write_str(self.as_str())
33    }
34}
35
36impl From<PlaybackStatus> for Variant<'_> {
37    fn from(status: PlaybackStatus) -> Self {
38        Variant::new(status.as_str())
39    }
40}