diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-03-30 11:21:38 +0200 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-03-30 15:25:56 +0200 |
| commit | e1907114374c842654f86b234b816f57dbbc79d4 (patch) | |
| tree | 92595ffb0be7afcd19c7a2150010374f988b711a /mumd/src/error.rs | |
| parent | 8c3a37b40260711ef13a6130a612537b64b78215 (diff) | |
| download | mum-e1907114374c842654f86b234b816f57dbbc79d4.tar.gz | |
add StateError and AudioError
Diffstat (limited to 'mumd/src/error.rs')
| -rw-r--r-- | mumd/src/error.rs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/mumd/src/error.rs b/mumd/src/error.rs new file mode 100644 index 0000000..a171f1f --- /dev/null +++ b/mumd/src/error.rs @@ -0,0 +1,54 @@ +use std::fmt; + +pub enum AudioStream { + Input, + Output, +} + +impl fmt::Display for AudioStream { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + AudioStream::Input => write!(f, "input"), + AudioStream::Output => write!(f, "output"), + } + } +} + +pub enum AudioError { + NoDevice(AudioStream), + NoConfigs(AudioStream, cpal::SupportedStreamConfigsError), + NoSupportedConfig(AudioStream), + InvalidStream(AudioStream, cpal::BuildStreamError), + OutputPlayError(cpal::PlayStreamError), +} + +impl fmt::Display for AudioError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + AudioError::NoDevice(s) => write!(f, "No {} device", s), + AudioError::NoConfigs(s, e) => write!(f, "No {} configs: {}", s, e), + AudioError::NoSupportedConfig(s) => write!(f, "No supported {} config found", s), + AudioError::InvalidStream(s, e) => write!(f, "Invalid {} stream: {}", s, e), + AudioError::OutputPlayError(e) => write!(f, "Playback error: {}", e), + } + } +} + +pub enum StateError { + AudioError(AudioError), +} + +impl From<AudioError> for StateError { + fn from(e: AudioError) -> Self { + StateError::AudioError(e) + } +} + +impl fmt::Display for StateError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + StateError::AudioError(e) => write!(f, "Audio error: {}", e), + } + } +} + |
