From 6e9b40e225cf8cc67e0448a6e818fc25e9feb31f Mon Sep 17 00:00:00 2001 From: mitchmindtree Date: Mon, 24 Jun 2019 22:49:18 +0200 Subject: [PATCH] Minimize compiler flags by using nested platform_impl mods Also addresses some other CI errors: - Add Host::new constructor for null backend - Add missing DevicesError import to coreaudio backend --- src/host/coreaudio/mod.rs | 1 + src/host/null/mod.rs | 6 ++++ src/platform/mod.rs | 63 +++++++++++++++++++++++++-------------- 3 files changed, 48 insertions(+), 22 deletions(-) diff --git a/src/host/coreaudio/mod.rs b/src/host/coreaudio/mod.rs index d37de7bd5..85da95e83 100644 --- a/src/host/coreaudio/mod.rs +++ b/src/host/coreaudio/mod.rs @@ -7,6 +7,7 @@ use BuildStreamError; use DefaultFormatError; use Device as DeviceTrait; use DeviceNameError; +use DevicesError; use EventLoop as EventLoopTrait; use Format; use Host as HostTrait; diff --git a/src/host/null/mod.rs b/src/host/null/mod.rs index 45b6b9b0c..d45200f4d 100644 --- a/src/host/null/mod.rs +++ b/src/host/null/mod.rs @@ -31,6 +31,12 @@ pub struct StreamId; pub struct SupportedInputFormats; pub struct SupportedOutputFormats; +impl Host { + pub fn new() -> Result { + Ok(Host) + } +} + impl Devices { pub fn new() -> Result { Ok(Devices) diff --git a/src/platform/mod.rs b/src/platform/mod.rs index ef6a635b4..0327aea98 100644 --- a/src/platform/mod.rs +++ b/src/platform/mod.rs @@ -4,6 +4,9 @@ //! type and its associated `EventLoop`, `Device`, `StreamId` and other associated types. These //! types are useful in the case that users require switching between audio host APIs at runtime. +#[doc(inline)] +pub use self::platform_impl::*; + // A macro to assist with implementing a platform's dynamically dispatched `Host` type. // // These dynamically dispatched types are necessary to allow for users to switch between hosts at @@ -412,41 +415,57 @@ macro_rules! impl_platform_host { // TODO: Add pulseaudio and jack here eventually. #[cfg(any(target_os = "linux", target_os = "freebsd"))] -impl_platform_host!(Alsa alsa); +mod platform_impl { + pub use crate::host::alsa::Host as AlsaHost; + + /// The default host for the current compilation target platform. + pub type DefaultHost = crate::host::alsa::Host; + + impl_platform_host!(Alsa alsa); +} + #[cfg(any(target_os = "macos", target_os = "ios"))] -impl_platform_host!(CoreAudio coreaudio); +mod platform_impl { + pub use crate::host::coreaudio::Host as CoreAudioHost; + + /// The default host for the current compilation target platform. + pub type DefaultHost = crate::host::coreaudio::Host; + + impl_platform_host!(CoreAudio coreaudio); +} #[cfg(target_os = "emscripten")] -impl_platform_host!(Emscripten emscripten); +mod platform_impl { + pub use crate::host::emscripten::Host as EmscriptenHost; -// TODO: Add `Asio asio` once #221 lands. -#[cfg(windows)] -impl_platform_host!(Wasapi wasapi); + /// The default host for the current compilation target platform. + pub type DefaultHost = crate::host::emscripten::Host; -#[cfg(not(any(windows, target_os = "linux", target_os = "freebsd", target_os = "macos", - target_os = "ios", target_os = "emscripten")))] -impl_platform_host!(Null null); + impl_platform_host!(Emscripten emscripten); +} -/// The default host for the current compilation target platform. -#[cfg(any(target_os = "linux", target_os = "freebsd"))] -pub type DefaultHost = crate::host::alsa::Host; +// TODO: Add `Asio asio` once #221 lands. +#[cfg(windows)] +mod platform_impl { + pub use crate::host::wasapi::Host as WasapiHost; -/// The default host for the current compilation target platform. -#[cfg(any(target_os = "macos", target_os = "ios"))] -pub type DefaultHost = crate::host::coreaudio::Host; + /// The default host for the current compilation target platform. + pub type DefaultHost = crate::host::wasapi::Host; -/// The default host for the current compilation target platform. -#[cfg(target_os = "emscripten")] -pub type DefaultHost = crate::host::emscripten::Host; + impl_platform_host!(Wasapi wasapi); +} #[cfg(not(any(windows, target_os = "linux", target_os = "freebsd", target_os = "macos", target_os = "ios", target_os = "emscripten")))] -pub type DefaultHost = crate::host::null::Host; +mod platform_impl { + pub use crate::host::null::Host as NullHost; -/// The default host for the current compilation target platform. -#[cfg(windows)] -pub type DefaultHost = crate::host::wasapi::Host; + /// The default host for the current compilation target platform. + pub type DefaultHost = crate::host::null::Host; + + impl_platform_host!(Null null); +} /// Retrieve the default host for the system. ///