pipewire/
error.rs

1// Copyright The pipewire-rs Contributors.
2// SPDX-License-Identifier: MIT
3
4#[derive(Debug)]
5pub enum Error {
6    CreationFailed,
7    NoMemory,
8    WrongProxyType,
9    SpaError(spa::utils::result::Error),
10}
11
12impl std::error::Error for Error {
13    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
14        match self {
15            Self::CreationFailed => None,
16            Self::NoMemory => None,
17            Self::WrongProxyType => None,
18            Self::SpaError(error) => Some(error),
19        }
20    }
21}
22
23impl std::fmt::Display for Error {
24    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25        match self {
26            Self::CreationFailed => f.write_str("Creation failed"),
27            Self::NoMemory => f.write_str("No memory"),
28            Self::WrongProxyType => f.write_str("Wrong proxy type"),
29            Self::SpaError(error) => write!(f, "{}", error),
30        }
31    }
32}
33
34impl From<spa::utils::result::Error> for Error {
35    fn from(value: spa::utils::result::Error) -> Self {
36        Self::SpaError(value)
37    }
38}