Add new DeviceNameError type
The coreaudio and wasapi backends may both potentially fail to produce the name associated with a device. This changes the API to allow for returning the errors in these cases.
This commit is contained in:
parent
78a7cb9e79
commit
105086a108
6 changed files with 54 additions and 19 deletions
19
src/lib.rs
19
src/lib.rs
|
|
@ -308,6 +308,17 @@ pub enum DevicesError {
|
|||
}
|
||||
}
|
||||
|
||||
/// An error that may occur while attempting to retrieve a device name.
|
||||
#[derive(Debug, Fail)]
|
||||
pub enum DeviceNameError {
|
||||
/// See the `BackendSpecificError` docs for more information about this error variant.
|
||||
#[fail(display = "{}", err)]
|
||||
BackendSpecific {
|
||||
#[fail(cause)]
|
||||
err: BackendSpecificError,
|
||||
}
|
||||
}
|
||||
|
||||
/// Error that can happen when enumerating the list of supported formats.
|
||||
#[derive(Debug, Fail)]
|
||||
pub enum SupportedFormatsError {
|
||||
|
|
@ -410,7 +421,7 @@ pub fn default_output_device() -> Option<Device> {
|
|||
impl Device {
|
||||
/// The human-readable name of the device.
|
||||
#[inline]
|
||||
pub fn name(&self) -> String {
|
||||
pub fn name(&self) -> Result<String, DeviceNameError> {
|
||||
self.0.name()
|
||||
}
|
||||
|
||||
|
|
@ -742,6 +753,12 @@ impl From<BackendSpecificError> for DevicesError {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<BackendSpecificError> for DeviceNameError {
|
||||
fn from(err: BackendSpecificError) -> Self {
|
||||
DeviceNameError::BackendSpecific { err }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<BackendSpecificError> for SupportedFormatsError {
|
||||
fn from(err: BackendSpecificError) -> Self {
|
||||
SupportedFormatsError::BackendSpecific { err }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue