1use std::error::Error;
2use std::fmt::{Display, Formatter};
3
4#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
6pub struct HostUnavailable;
7
8impl Display for HostUnavailable {
9 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
10 f.write_str("the requested host is unavailable")
11 }
12}
13
14impl Error for HostUnavailable {}
15
16#[derive(Clone, Debug, PartialEq, Eq, Hash)]
29pub struct BackendSpecificError {
30 pub description: String,
31}
32
33impl Display for BackendSpecificError {
34 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
35 write!(
36 f,
37 "A backend-specific error has occurred: {}",
38 self.description
39 )
40 }
41}
42
43impl Error for BackendSpecificError {}
44
45#[derive(Clone, Debug, PartialEq, Eq, Hash)]
47pub enum DevicesError {
48 BackendSpecific { err: BackendSpecificError },
50}
51
52impl Display for DevicesError {
53 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
54 match self {
55 Self::BackendSpecific { err } => err.fmt(f),
56 }
57 }
58}
59
60impl Error for DevicesError {}
61
62impl From<BackendSpecificError> for DevicesError {
63 fn from(err: BackendSpecificError) -> Self {
64 Self::BackendSpecific { err }
65 }
66}
67
68#[derive(Clone, Debug, PartialEq, Eq, Hash)]
70pub enum DeviceNameError {
71 BackendSpecific { err: BackendSpecificError },
73}
74
75impl Display for DeviceNameError {
76 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
77 match self {
78 Self::BackendSpecific { err } => err.fmt(f),
79 }
80 }
81}
82
83impl Error for DeviceNameError {}
84
85impl From<BackendSpecificError> for DeviceNameError {
86 fn from(err: BackendSpecificError) -> Self {
87 Self::BackendSpecific { err }
88 }
89}
90
91#[derive(Clone, Debug, PartialEq, Eq, Hash)]
93pub enum SupportedStreamConfigsError {
94 DeviceNotAvailable,
97 InvalidArgument,
99 BackendSpecific { err: BackendSpecificError },
101}
102
103impl Display for SupportedStreamConfigsError {
104 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
105 match self {
106 Self::BackendSpecific { err } => err.fmt(f),
107 Self::DeviceNotAvailable => f.write_str("The requested device is no longer available. For example, it has been unplugged."),
108 Self::InvalidArgument => f.write_str("Invalid argument passed to the backend. For example, this happens when trying to read capture capabilities when the device does not support it.")
109 }
110 }
111}
112
113impl Error for SupportedStreamConfigsError {}
114
115impl From<BackendSpecificError> for SupportedStreamConfigsError {
116 fn from(err: BackendSpecificError) -> Self {
117 Self::BackendSpecific { err }
118 }
119}
120
121#[derive(Clone, Debug, PartialEq, Eq, Hash)]
123pub enum DefaultStreamConfigError {
124 DeviceNotAvailable,
127 StreamTypeNotSupported,
129 BackendSpecific { err: BackendSpecificError },
131}
132
133impl Display for DefaultStreamConfigError {
134 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
135 match self {
136 Self::BackendSpecific { err } => err.fmt(f),
137 Self::DeviceNotAvailable => f.write_str(
138 "The requested device is no longer available. For example, it has been unplugged.",
139 ),
140 Self::StreamTypeNotSupported => {
141 f.write_str("The requested stream type is not supported by the device.")
142 }
143 }
144 }
145}
146
147impl Error for DefaultStreamConfigError {}
148
149impl From<BackendSpecificError> for DefaultStreamConfigError {
150 fn from(err: BackendSpecificError) -> Self {
151 Self::BackendSpecific { err }
152 }
153}
154#[derive(Clone, Debug, PartialEq, Eq, Hash)]
156pub enum BuildStreamError {
157 DeviceNotAvailable,
160 StreamConfigNotSupported,
162 InvalidArgument,
167 StreamIdOverflow,
169 BackendSpecific { err: BackendSpecificError },
171}
172
173impl Display for BuildStreamError {
174 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
175 match self {
176 Self::BackendSpecific { err } => err.fmt(f),
177 Self::DeviceNotAvailable => f.write_str(
178 "The requested device is no longer available. For example, it has been unplugged.",
179 ),
180 Self::StreamConfigNotSupported => {
181 f.write_str("The requested stream configuration is not supported by the device.")
182 }
183 Self::InvalidArgument => f.write_str(
184 "The requested device does not support this capability (invalid argument)",
185 ),
186 Self::StreamIdOverflow => f.write_str("Adding a new stream ID would cause an overflow"),
187 }
188 }
189}
190
191impl Error for BuildStreamError {}
192
193impl From<BackendSpecificError> for BuildStreamError {
194 fn from(err: BackendSpecificError) -> Self {
195 Self::BackendSpecific { err }
196 }
197}
198
199#[derive(Clone, Debug, PartialEq, Eq, Hash)]
205pub enum PlayStreamError {
206 DeviceNotAvailable,
208 BackendSpecific { err: BackendSpecificError },
210}
211
212impl Display for PlayStreamError {
213 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
214 match self {
215 Self::BackendSpecific { err } => err.fmt(f),
216 Self::DeviceNotAvailable => {
217 f.write_str("the device associated with the stream is no longer available")
218 }
219 }
220 }
221}
222
223impl Error for PlayStreamError {}
224
225impl From<BackendSpecificError> for PlayStreamError {
226 fn from(err: BackendSpecificError) -> Self {
227 Self::BackendSpecific { err }
228 }
229}
230
231#[derive(Clone, Debug, PartialEq, Eq, Hash)]
237pub enum PauseStreamError {
238 DeviceNotAvailable,
240 BackendSpecific { err: BackendSpecificError },
242}
243
244impl Display for PauseStreamError {
245 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
246 match self {
247 Self::BackendSpecific { err } => err.fmt(f),
248 Self::DeviceNotAvailable => {
249 f.write_str("the device associated with the stream is no longer available")
250 }
251 }
252 }
253}
254
255impl Error for PauseStreamError {}
256
257impl From<BackendSpecificError> for PauseStreamError {
258 fn from(err: BackendSpecificError) -> Self {
259 Self::BackendSpecific { err }
260 }
261}
262
263#[derive(Clone, Debug, PartialEq, Eq, Hash)]
265pub enum StreamError {
266 DeviceNotAvailable,
269 BackendSpecific { err: BackendSpecificError },
271}
272
273impl Display for StreamError {
274 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
275 match self {
276 Self::BackendSpecific { err } => err.fmt(f),
277 Self::DeviceNotAvailable => f.write_str(
278 "The requested device is no longer available. For example, it has been unplugged.",
279 ),
280 }
281 }
282}
283
284impl Error for StreamError {}
285
286impl From<BackendSpecificError> for StreamError {
287 fn from(err: BackendSpecificError) -> Self {
288 Self::BackendSpecific { err }
289 }
290}