Use function types instead of closures for backend builders.

This commit is contained in:
Paul Lietar 2017-02-21 22:05:31 +00:00
parent 5974cf7f24
commit 58b1625445

View file

@ -74,20 +74,19 @@ use self::pipe::StdoutSink;
declare_backends! { declare_backends! {
pub const BACKENDS : &'static [ pub const BACKENDS : &'static [
(&'static str, (&'static str, fn(Option<&str>) -> Box<Sink>)
&'static (Fn(Option<&str>) -> Box<Sink> + Sync + Send + 'static))
] = &[ ] = &[
#[cfg(feature = "alsa-backend")] #[cfg(feature = "alsa-backend")]
("alsa", &mk_sink::<AlsaSink>), ("alsa", mk_sink::<AlsaSink>),
#[cfg(feature = "portaudio-backend")] #[cfg(feature = "portaudio-backend")]
("portaudio", &mk_sink::<PortAudioSink>), ("portaudio", mk_sink::<PortAudioSink>),
#[cfg(feature = "pulseaudio-backend")] #[cfg(feature = "pulseaudio-backend")]
("pulseaudio", &mk_sink::<PulseAudioSink>), ("pulseaudio", mk_sink::<PulseAudioSink>),
("pipe", &mk_sink::<StdoutSink>), ("pipe", mk_sink::<StdoutSink>),
]; ];
} }
pub fn find<T: AsRef<str>>(name: Option<T>) -> Option<&'static (Fn(Option<&str>) -> Box<Sink> + Send + Sync)> { pub fn find<T: AsRef<str>>(name: Option<T>) -> Option<fn(Option<&str>) -> Box<Sink>> {
if let Some(name) = name.as_ref().map(AsRef::as_ref) { if let Some(name) = name.as_ref().map(AsRef::as_ref) {
BACKENDS.iter().find(|backend| name == backend.0).map(|backend| backend.1) BACKENDS.iter().find(|backend| name == backend.0).map(|backend| backend.1)
} else { } else {