mpris_server/
loop_status.rs1use std::fmt;
2
3use zbus::zvariant::{self, Type, Value};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Type)]
7#[zvariant(signature = "s")]
8#[doc(alias = "Loop_Status")]
9pub enum LoopStatus {
10 None,
12 Track,
15 Playlist,
17}
18
19impl LoopStatus {
20 pub fn as_str(&self) -> &'static str {
22 match self {
23 Self::None => "None",
24 Self::Track => "Track",
25 Self::Playlist => "Playlist",
26 }
27 }
28}
29
30impl fmt::Display for LoopStatus {
31 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32 f.write_str(self.as_str())
33 }
34}
35
36impl<'a> TryFrom<Value<'a>> for LoopStatus {
37 type Error = zvariant::Error;
38
39 fn try_from(value: Value<'a>) -> Result<Self, Self::Error> {
40 match value {
41 Value::Str(s) => match s.as_str() {
42 "None" => Ok(Self::None),
43 "Track" => Ok(Self::Track),
44 "Playlist" => Ok(Self::Playlist),
45 _ => Err(zvariant::Error::Message(format!(
46 "invalid loop status: {}",
47 s
48 ))),
49 },
50 _ => Err(zvariant::Error::IncorrectType),
51 }
52 }
53}
54
55impl From<LoopStatus> for Value<'_> {
56 fn from(status: LoopStatus) -> Self {
57 Value::new(status.as_str())
58 }
59}