sbz_switch/soundcore/
error.rs

1use std::error::Error;
2use std::fmt;
3
4use crate::hresult::Win32Error;
5use crate::media::GetPropertyError;
6
7/// Describes an error that occurred while acting on Creative's SoundCore API.
8#[derive(Debug)]
9pub enum SoundCoreError {
10    /// Some Win32 error occurred.
11    Win32(Win32Error),
12    /// The specified device does not support implement the SoundCore API.
13    NotSupported,
14}
15
16impl fmt::Display for SoundCoreError {
17    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
18        match *self {
19            SoundCoreError::Win32(ref err) => write!(f, "Win32Error: {}", err),
20            SoundCoreError::NotSupported => write!(f, "SoundCore not supported"),
21        }
22    }
23}
24
25impl Error for SoundCoreError {
26    fn cause(&self) -> Option<&dyn Error> {
27        match *self {
28            SoundCoreError::Win32(ref err) => Some(err),
29            SoundCoreError::NotSupported => None,
30        }
31    }
32}
33
34impl From<Win32Error> for SoundCoreError {
35    fn from(err: Win32Error) -> SoundCoreError {
36        SoundCoreError::Win32(err)
37    }
38}
39
40impl From<GetPropertyError> for SoundCoreError {
41    fn from(err: GetPropertyError) -> SoundCoreError {
42        match err {
43            GetPropertyError::UnexpectedType(_) => SoundCoreError::NotSupported,
44            GetPropertyError::Win32(inner) => inner.into(),
45        }
46    }
47}