From 77ce5eba06447275ce6a094ac053e6775272ad8c Mon Sep 17 00:00:00 2001 From: Nitori Date: Sat, 30 Jun 2018 04:51:24 -0500 Subject: [PATCH] Implement Display and Error for DefaultFormatError (#230) --- src/lib.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index e801fee..e7f8e8b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -740,6 +740,28 @@ impl Error for CreationError { } } +impl fmt::Display for DefaultFormatError { + #[inline] + fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> { + write!(fmt, "{}", self.description()) + } +} + +impl Error for DefaultFormatError { + #[inline] + fn description(&self) -> &str { + match self { + &DefaultFormatError::DeviceNotAvailable => { + CreationError::DeviceNotAvailable.description() + }, + + &DefaultFormatError::StreamTypeNotSupported => { + "The requested stream type is not supported by the device." + }, + } + } +} + // If a backend does not provide an API for retrieving supported formats, we query it with a bunch // of commonly used rates. This is always the case for wasapi and is sometimes the case for alsa. //