1#![warn(missing_docs)]
2#![deny(
3 missing_debug_implementations,
4 missing_copy_implementations,
5 trivial_casts,
6 trivial_numeric_casts,
7 unsafe_code,
8 unreachable_pub,
9 unstable_features,
10 unused_import_braces,
11 unused_qualifications
12)]
13
14use thiserror::Error;
31
32mod extensions;
33
34#[allow(unreachable_pub)]
35mod generated;
36
37mod event;
38mod find;
39mod metadata;
40mod player;
41mod pooled_connection;
42mod progress;
43mod track_list;
44
45pub use crate::event::{Event, EventError, PlayerEvents};
46pub use crate::find::{FindingError, PlayerFinder, PlayerIter};
47pub use crate::metadata::Metadata;
48pub use crate::metadata::Value as MetadataValue;
49pub use crate::metadata::ValueKind as MetadataValueKind;
50pub use crate::player::Player;
51pub use crate::progress::{Progress, ProgressError, ProgressTick, ProgressTracker};
52pub use crate::track_list::{TrackID, TrackList, TrackListError};
53
54#[derive(Debug, PartialEq, Eq, Copy, Clone)]
55#[allow(missing_docs)]
56pub enum PlaybackStatus {
62 Playing,
64 Paused,
66 Stopped,
68}
69
70#[derive(Debug, PartialEq, Eq, Copy, Clone)]
71pub enum LoopStatus {
77 None,
79
80 Track,
82
83 Playlist,
85}
86
87#[derive(Debug, Error)]
89#[error("PlaybackStatus must be one of Playing, Paused, Stopped, but was {0}")]
90pub struct InvalidPlaybackStatus(String);
91
92impl ::std::str::FromStr for PlaybackStatus {
93 type Err = InvalidPlaybackStatus;
94
95 fn from_str(string: &str) -> Result<Self, Self::Err> {
96 use crate::PlaybackStatus::*;
97
98 match string {
99 "Playing" => Ok(Playing),
100 "Paused" => Ok(Paused),
101 "Stopped" => Ok(Stopped),
102 other => Err(InvalidPlaybackStatus(other.to_string())),
103 }
104 }
105}
106
107#[derive(Debug, Error)]
109#[error("LoopStatus must be one of None, Track, Playlist, but was {0}")]
110pub struct InvalidLoopStatus(String);
111
112impl ::std::str::FromStr for LoopStatus {
113 type Err = InvalidLoopStatus;
114
115 fn from_str(string: &str) -> Result<Self, Self::Err> {
116 match string {
117 "None" => Ok(LoopStatus::None),
118 "Track" => Ok(LoopStatus::Track),
119 "Playlist" => Ok(LoopStatus::Playlist),
120 other => Err(InvalidLoopStatus(other.to_string())),
121 }
122 }
123}
124
125impl LoopStatus {
126 fn dbus_value(self) -> String {
127 String::from(match self {
128 LoopStatus::None => "None",
129 LoopStatus::Track => "Track",
130 LoopStatus::Playlist => "Playlist",
131 })
132 }
133}
134
135#[derive(Debug, Error)]
138pub enum DBusError {
139 #[error("D-Bus call failed: {0}")]
141 TransportError(#[from] dbus::Error),
142
143 #[error("Failed to parse enum value: {0}")]
146 EnumParseError(String),
147
148 #[error("D-Bus call failed: {0}")]
151 TypeMismatchError(#[from] dbus::arg::TypeMismatchError),
152
153 #[error("Unexpected error: {0}")]
155 Miscellaneous(String),
156}
157
158impl From<InvalidPlaybackStatus> for DBusError {
159 fn from(error: InvalidPlaybackStatus) -> Self {
160 DBusError::EnumParseError(error.to_string())
161 }
162}
163
164impl From<InvalidLoopStatus> for DBusError {
165 fn from(error: InvalidLoopStatus) -> Self {
166 DBusError::EnumParseError(error.to_string())
167 }
168}