Repository: RustAudio/rust-portaudio (language: rust)

Issue:
Replace try!() with ?



Discussion / hints:

Fix patch:
diff --git a/examples/blocking.rs b/examples/blocking.rs
index e3025e7..742c0c1 100644
--- a/examples/blocking.rs
+++ b/examples/blocking.rs
@@ -8,16 +8,14 @@ extern crate portaudio;
 use portaudio as pa;
 use std::collections::VecDeque;
 
-
 const SAMPLE_RATE: f64 = 44_100.0;
 const CHANNELS: i32 = 2;
 const FRAMES: u32 = 256;
 const INTERLEAVED: bool = true;
 
-
 fn main() {
     match run() {
-        Ok(_) => {},
+        Ok(_) => {}
         e => {
             eprintln!("Example failed with the following: {:?}", e);
         }
@@ -25,58 +23,64 @@ fn main() {
 }
 
 fn run() -> Result<(), pa::Error> {
-
-    let pa = try!(pa::PortAudio::new());
+    let pa = pa::PortAudio::new()?;
 
     println!("PortAudio");
     println!("version: {}", pa.version());
     println!("version text: {:?}", pa.version_text());
-    println!("host count: {}", try!(pa.host_api_count()));
+    println!("host count: {}", pa.host_api_count()?);
 
-    let default_host = try!(pa.default_host_api());
+    let default_host = pa.default_host_api()?;
     println!("default host: {:#?}", pa.host_api_info(default_host));
 
-    let def_input = try!(pa.default_input_device());
-    let input_info = try!(pa.device_info(def_input));
+    let def_input = pa.default_input_device()?;
+    let input_info = pa.device_info(def_input)?;
     println!("Default input device info: {:#?}", &input_info);
 
     // Construct the input stream parameters.
     let latency = input_info.default_low_input_latency;
     let input_params = pa::StreamParameters::<f32>::new(def_input, CHANNELS, INTERLEAVED, latency);
 
-    let def_output = try!(pa.default_output_device());
-    let output_info = try!(pa.device_info(def_output));
+    let def_output = pa.default_output_device()?;
+    let output_info = pa.device_info(def_output)?;
     println!("Default output device info: {:#?}", &output_info);
 
     // Construct the output stream parameters.
     let latency = output_info.default_low_output_latency;
-    let output_params = pa::StreamParameters::<f32>::new(def_output, CHANNELS, INTERLEAVED, latency);
+    let output_params =
+        pa::StreamParameters::<f32>::new(def_output, CHANNELS, INTERLEAVED, latency);
 
     // Check that the stream format is supported.
-    try!(pa.is_duplex_format_supported(input_params, output_params, SAMPLE_RATE));
+    pa.is_duplex_format_supported(input_params, output_params, SAMPLE_RATE)?;
 
     // Construct the settings with which we'll open our duplex stream.
     let settings = pa::DuplexStreamSettings::new(input_params, output_params, SAMPLE_RATE, FRAMES);
 
-    let mut stream = try!(pa.open_blocking_stream(settings));
+    let mut stream = pa.open_blocking_stream(settings)?;
 
     // We'll use this buffer to transfer samples from the input stream to the output stream.
     let mut buffer: VecDeque<f32> = VecDeque::with_capacity(FRAMES as usize * CHANNELS as usize);
 
-    try!(stream.start());
+    stream.start()?;
 
     // We'll use this function to wait for read/write availability.
     fn wait_for_stream<F>(f: F, name: &str) -> u32
-        where F: Fn() -> Result<pa::StreamAvailable, pa::error::Error>
+    where
+        F: Fn() -> Result<pa::StreamAvailable, pa::error::Error>,
     {
         'waiting_for_stream: loop {
             match f() {
                 Ok(available) => match available {
                     pa::StreamAvailable::Frames(frames) => return frames as u32,
                     pa::StreamAvailable::InputOverflowed => println!("Input stream has overflowed"),
-                    pa::StreamAvailable::OutputUnderflowed => println!("Output stream has underflowed"),
+                    pa::StreamAvailable::OutputUnderflowed => {
+                        println!("Output stream has underflowed")
+                    }
                 },
-                Err(err) => panic!("An error occurred while waiting for the {} stream: {}", name, err),
+                Err(err) => panic!(
+                    "An error occurred while waiting for the {} stream: {}",
+                    name, err
+                ),
             }
         }
     };
@@ -84,13 +88,12 @@ fn run() -> Result<(), pa::Error> {
     // Now start the main read/write loop! In this example, we pass the input buffer directly to
     // the output buffer, so watch out for feedback.
     'stream: loop {
-
         // How many frames are available on the input stream?
         let in_frames = wait_for_stream(|| stream.read_available(), "Read");
 
         // If there are frames available, let's take them and add them to our buffer.
         if in_frames > 0 {
-            let input_samples = try!(stream.read(in_frames));
+            let input_samples = stream.read(in_frames)?;
             buffer.extend(input_samples.into_iter());
             println!("Read {:?} frames from the input stream.", in_frames);
         }
@@ -103,20 +106,21 @@ fn run() -> Result<(), pa::Error> {
 
         // If there are frames available for writing and we have some to write, then write!
         if out_frames > 0 && buffer_frames > 0 {
-
             // If we have more than enough frames for writing, take them from the start of the buffer.
             // Otherwise if we have less, just take what we can for now.
-            let write_frames = if buffer_frames >= out_frames { out_frames } else { buffer_frames };
+            let write_frames = if buffer_frames >= out_frames {
+                out_frames
+            } else {
+                buffer_frames
+            };
             let n_write_samples = write_frames as usize * CHANNELS as usize;
 
-            try!(stream.write(write_frames, |output| {
+            stream.write(write_frames, |output| {
                 for i in 0..n_write_samples {
                     output[i] = buffer.pop_front().unwrap();
                 }
                 println!("Wrote {:?} frames to the output stream.", out_frames);
-            }));
+            })?;
         }
-
     }
-
 }
diff --git a/examples/devices.rs b/examples/devices.rs
index 6f2affe..5b36d92 100644
--- a/examples/devices.rs
+++ b/examples/devices.rs
@@ -3,56 +3,65 @@
 extern crate portaudio;
 use portaudio as pa;
 
-
 const INTERLEAVED: bool = true;
 const LATENCY: pa::Time = 0.0; // Ignored by PortAudio::is_*_format_supported.
 const STANDARD_SAMPLE_RATES: [f64; 13] = [
-    8000.0, 9600.0, 11025.0, 12000.0, 16000.0, 22050.0, 24000.0, 32000.0,
-    44100.0, 48000.0, 88200.0, 96000.0, 192000.0,
+    8000.0, 9600.0, 11025.0, 12000.0, 16000.0, 22050.0, 24000.0, 32000.0, 44100.0, 48000.0,
+    88200.0, 96000.0, 192000.0,
 ];
 
-
 fn main() {
     match run() {
-        Ok(_) => {},
+        Ok(_) => {}
         e => {
             eprintln!("Example failed with the following: {:?}", e);
         }
     }
 }
 
-
 fn run() -> Result<(), pa::Error> {
+    let pa = pa::PortAudio::new()?;
 
-    let pa = try!(pa::PortAudio::new());
-
-    let num_devices = try!(pa.device_count());
+    let num_devices = pa.device_count()?;
     println!("Number of devices = {}", num_devices);
 
     println!("Defualt input device: {:?}", pa.default_input_device());
     println!("Defualt output device: {:?}", pa.default_output_device());
 
     println!("All devices:");
-    for device in try!(pa.devices()) {
-        let (idx, info) = try!(device);
+    for device in pa.devices()? {
+        let (idx, info) = device?;
         println!("--------------------------------------- {:?}", idx);
         println!("{:#?}", &info);
 
         let in_channels = info.max_input_channels;
         let input_params = pa::StreamParameters::<i16>::new(idx, in_channels, INTERLEAVED, LATENCY);
         let out_channels = info.max_output_channels;
-        let output_params = pa::StreamParameters::<i16>::new(idx, out_channels, INTERLEAVED, LATENCY);
+        let output_params =
+            pa::StreamParameters::<i16>::new(idx, out_channels, INTERLEAVED, LATENCY);
 
-        println!("Supported standard sample rates for half-duplex 16-bit {} channel input:", in_channels);
+        println!(
+            "Supported standard sample rates for half-duplex 16-bit {} channel input:",
+            in_channels
+        );
         for &sample_rate in &STANDARD_SAMPLE_RATES {
-            if pa.is_input_format_supported(input_params, sample_rate).is_ok() {
+            if pa
+                .is_input_format_supported(input_params, sample_rate)
+                .is_ok()
+            {
                 println!("\t{}hz", sample_rate);
             }
         }
 
-        println!("Supported standard sample rates for half-duplex 16-bit {} channel output:", out_channels);
+        println!(
+            "Supported standard sample rates for half-duplex 16-bit {} channel output:",
+            out_channels
+        );
         for &sample_rate in &STANDARD_SAMPLE_RATES {
-            if pa.is_output_format_supported(output_params, sample_rate).is_ok() {
+            if pa
+                .is_output_format_supported(output_params, sample_rate)
+                .is_ok()
+            {
                 println!("\t{}hz", sample_rate);
             }
         }
@@ -60,7 +69,10 @@ fn run() -> Result<(), pa::Error> {
         println!("Supported standard sample rates for full-duplex 16-bit {} channel input, {} channel output:",
                  in_channels, out_channels);
         for &sample_rate in &STANDARD_SAMPLE_RATES {
-            if pa.is_duplex_format_supported(input_params, output_params, sample_rate).is_ok() {
+            if pa
+                .is_duplex_format_supported(input_params, output_params, sample_rate)
+                .is_ok()
+            {
                 println!("\t{}hz", sample_rate);
             }
         }
diff --git a/examples/fuzz.rs b/examples/fuzz.rs
index 06778ad..4e0d473 100644
--- a/examples/fuzz.rs
+++ b/examples/fuzz.rs
@@ -8,23 +8,20 @@ extern crate portaudio;
 
 use portaudio as pa;
 
-
 const SAMPLE_RATE: f64 = 44_100.0;
 const FRAMES: u32 = 64;
 const CHANNELS: i32 = 2;
 const INTERLEAVED: bool = true;
 
-
 fn main() {
     match run() {
-        Ok(_) => {},
+        Ok(_) => {}
         e => {
             eprintln!("Example failed with the following: {:?}", e);
         }
     }
 }
 
-
 // the fuzz filter, when applied to all samples, will add some
 // distortion
 fn fuzz(input: f32) -> f32 {
@@ -49,27 +46,26 @@ fn cubic_amplifier(input: f32) -> f32 {
 }
 
 fn run() -> Result<(), pa::Error> {
-
-    let pa = try!(pa::PortAudio::new());
+    let pa = pa::PortAudio::new()?;
 
     println!("PortAudio:");
     println!("version: {}", pa.version());
     println!("version text: {:?}", pa.version_text());
-    println!("host count: {}", try!(pa.host_api_count()));
+    println!("host count: {}", pa.host_api_count()?);
 
-    let default_host = try!(pa.default_host_api());
+    let default_host = pa.default_host_api()?;
     println!("default host: {:#?}", pa.host_api_info(default_host));
 
-    let def_input = try!(pa.default_input_device());
-    let input_info = try!(pa.device_info(def_input));
+    let def_input = pa.default_input_device()?;
+    let input_info = pa.device_info(def_input)?;
     println!("Default input device info: {:#?}", &input_info);
 
     // Construct the input stream parameters.
     let latency = input_info.default_low_input_latency;
     let input_params = pa::StreamParameters::<f32>::new(def_input, CHANNELS, INTERLEAVED, latency);
 
-    let def_output = try!(pa.default_output_device());
-    let output_info = try!(pa.device_info(def_output));
+    let def_output = pa.default_output_device()?;
+    let output_info = pa.device_info(def_output)?;
     println!("Default output device info: {:#?}", &output_info);
 
     // Construct the output stream parameters.
@@ -77,7 +73,7 @@ fn run() -> Result<(), pa::Error> {
     let output_params = pa::StreamParameters::new(def_output, CHANNELS, INTERLEAVED, latency);
 
     // Check that the stream format is supported.
-    try!(pa.is_duplex_format_supported(input_params, output_params, SAMPLE_RATE));
+    pa.is_duplex_format_supported(input_params, output_params, SAMPLE_RATE)?;
 
     // Construct the settings with which we'll open our duplex stream.
     let settings = pa::DuplexStreamSettings::new(input_params, output_params, SAMPLE_RATE, FRAMES);
@@ -92,7 +88,13 @@ fn run() -> Result<(), pa::Error> {
     let (sender, receiver) = ::std::sync::mpsc::channel();
 
     // A callback to pass to the non-blocking stream.
-    let callback = move |pa::DuplexStreamCallbackArgs { in_buffer, out_buffer, frames, time, .. }| {
+    let callback = move |pa::DuplexStreamCallbackArgs {
+                             in_buffer,
+                             out_buffer,
+                             frames,
+                             time,
+                             ..
+                         }| {
         let current_time = time.current;
         let prev_time = maybe_last_time.unwrap_or(current_time);
         let dt = current_time - prev_time;
@@ -108,25 +110,27 @@ fn run() -> Result<(), pa::Error> {
             *output_sample = fuzz(*input_sample);
         }
 
-        if count_down > 0.0 { pa::Continue } else { pa::Complete }
+        if count_down > 0.0 {
+            pa::Continue
+        } else {
+            pa::Complete
+        }
     };
 
     // Construct a stream with input and output sample types of f32.
-    let mut stream = try!(pa.open_non_blocking_stream(settings, callback));
+    let mut stream = pa.open_non_blocking_stream(settings, callback)?;
 
-    try!(stream.start());
+    stream.start()?;
 
     // Loop while the non-blocking stream is active.
-    while let true = try!(stream.is_active()) {
-
+    while let true = stream.is_active()? {
         // Watch the countdown while we wait for the stream to finish
         while let Ok(count_down) = receiver.try_recv() {
             println!("count_down: {:?}", count_down);
         }
-
     }
 
-    try!(stream.stop());
+    stream.stop()?;
 
     Ok(())
 }
diff --git a/examples/hosts.rs b/examples/hosts.rs
index e84228e..e49c7d8 100644
--- a/examples/hosts.rs
+++ b/examples/hosts.rs
@@ -5,7 +5,7 @@ extern crate portaudio as pa;
 
 fn main() {
     match run() {
-        Ok(_) => {},
+        Ok(_) => {}
         e => {
             eprintln!("Example failed with the following: {:?}", e);
         }
@@ -13,7 +13,7 @@ fn main() {
 }
 
 fn run() -> Result<(), pa::Error> {
-    let pa = try!(pa::PortAudio::new());
+    let pa = pa::PortAudio::new()?;
 
     println!("Default Host API: {:?}", pa.default_host_api());
     println!("All Host APIs:");
diff --git a/examples/non_blocking.rs b/examples/non_blocking.rs
index 038bdb0..4a322c3 100644
--- a/examples/non_blocking.rs
+++ b/examples/non_blocking.rs
@@ -7,16 +7,14 @@ extern crate portaudio;
 
 use portaudio as pa;
 
-
 const SAMPLE_RATE: f64 = 44_100.0;
 const FRAMES: u32 = 256;
 const CHANNELS: i32 = 2;
 const INTERLEAVED: bool = true;
 
-
 fn main() {
     match run() {
-        Ok(_) => {},
+        Ok(_) => {}
         e => {
             eprintln!("Example failed with the following: {:?}", e);
         }
@@ -24,27 +22,26 @@ fn main() {
 }
 
 fn run() -> Result<(), pa::Error> {
-
-    let pa = try!(pa::PortAudio::new());
+    let pa = pa::PortAudio::new()?;
 
     println!("PortAudio:");
     println!("version: {}", pa.version());
     println!("version text: {:?}", pa.version_text());
-    println!("host count: {}", try!(pa.host_api_count()));
+    println!("host count: {}", pa.host_api_count()?);
 
-    let default_host = try!(pa.default_host_api());
+    let default_host = pa.default_host_api()?;
     println!("default host: {:#?}", pa.host_api_info(default_host));
 
-    let def_input = try!(pa.default_input_device());
-    let input_info = try!(pa.device_info(def_input));
+    let def_input = pa.default_input_device()?;
+    let input_info = pa.device_info(def_input)?;
     println!("Default input device info: {:#?}", &input_info);
 
     // Construct the input stream parameters.
     let latency = input_info.default_low_input_latency;
     let input_params = pa::StreamParameters::<f32>::new(def_input, CHANNELS, INTERLEAVED, latency);
 
-    let def_output = try!(pa.default_output_device());
-    let output_info = try!(pa.device_info(def_output));
+    let def_output = pa.default_output_device()?;
+    let output_info = pa.device_info(def_output)?;
     println!("Default output device info: {:#?}", &output_info);
 
     // Construct the output stream parameters.
@@ -52,7 +49,7 @@ fn run() -> Result<(), pa::Error> {
     let output_params = pa::StreamParameters::new(def_output, CHANNELS, INTERLEAVED, latency);
 
     // Check that the stream format is supported.
-    try!(pa.is_duplex_format_supported(input_params, output_params, SAMPLE_RATE));
+    pa.is_duplex_format_supported(input_params, output_params, SAMPLE_RATE)?;
 
     // Construct the settings with which we'll open our duplex stream.
     let settings = pa::DuplexStreamSettings::new(input_params, output_params, SAMPLE_RATE, FRAMES);
@@ -67,7 +64,13 @@ fn run() -> Result<(), pa::Error> {
     let (sender, receiver) = ::std::sync::mpsc::channel();
 
     // A callback to pass to the non-blocking stream.
-    let callback = move |pa::DuplexStreamCallbackArgs { in_buffer, out_buffer, frames, time, .. }| {
+    let callback = move |pa::DuplexStreamCallbackArgs {
+                             in_buffer,
+                             out_buffer,
+                             frames,
+                             time,
+                             ..
+                         }| {
         let current_time = time.current;
         let prev_time = maybe_last_time.unwrap_or(current_time);
         let dt = current_time - prev_time;
@@ -82,25 +85,27 @@ fn run() -> Result<(), pa::Error> {
             *output_sample = *input_sample;
         }
 
-        if count_down > 0.0 { pa::Continue } else { pa::Complete }
+        if count_down > 0.0 {
+            pa::Continue
+        } else {
+            pa::Complete
+        }
     };
 
     // Construct a stream with input and output sample types of f32.
-    let mut stream = try!(pa.open_non_blocking_stream(settings, callback));
+    let mut stream = pa.open_non_blocking_stream(settings, callback)?;
 
-    try!(stream.start());
+    stream.start()?;
 
     // Loop while the non-blocking stream is active.
-    while let true = try!(stream.is_active()) {
-
+    while let true = stream.is_active()? {
         // Do some stuff!
         while let Ok(count_down) = receiver.try_recv() {
             println!("count_down: {:?}", count_down);
         }
-
     }
 
-    try!(stream.stop());
+    stream.stop()?;
 
     Ok(())
 }
diff --git a/examples/saw.rs b/examples/saw.rs
index 6bb41de..d4050fe 100644
--- a/examples/saw.rs
+++ b/examples/saw.rs
@@ -14,24 +14,26 @@ const FRAMES_PER_BUFFER: u32 = 64;
 
 fn main() {
     match run() {
-        Ok(_) => {},
+        Ok(_) => {}
         e => {
             eprintln!("Example failed with the following: {:?}", e);
         }
     }
 }
 
-
 fn run() -> Result<(), pa::Error> {
-
-    println!("PortAudio Test: output sawtooth wave. SR = {}, BufSize = {}", SAMPLE_RATE, FRAMES_PER_BUFFER);
+    println!(
+        "PortAudio Test: output sawtooth wave. SR = {}, BufSize = {}",
+        SAMPLE_RATE, FRAMES_PER_BUFFER
+    );
 
     let mut left_saw = 0.0;
     let mut right_saw = 0.0;
 
-    let pa = try!(pa::PortAudio::new());
+    let pa = pa::PortAudio::new()?;
 
-    let mut settings = try!(pa.default_output_stream_settings(CHANNELS, SAMPLE_RATE, FRAMES_PER_BUFFER));
+    let mut settings =
+        pa.default_output_stream_settings(CHANNELS, SAMPLE_RATE, FRAMES_PER_BUFFER)?;
     // we won't output out of range samples so don't bother clipping them.
     settings.flags = pa::stream_flags::CLIP_OFF;
 
@@ -42,25 +44,29 @@ fn run() -> Result<(), pa::Error> {
         let mut idx = 0;
         for _ in 0..frames {
             buffer[idx] = left_saw;
-            buffer[idx+1] = right_saw;
+            buffer[idx + 1] = right_saw;
             left_saw += 0.01;
-            if left_saw >= 1.0 { left_saw -= 2.0; }
+            if left_saw >= 1.0 {
+                left_saw -= 2.0;
+            }
             right_saw += 0.03;
-            if right_saw >= 1.0 { right_saw -= 2.0; }
+            if right_saw >= 1.0 {
+                right_saw -= 2.0;
+            }
             idx += 2;
         }
         pa::Continue
     };
 
-    let mut stream = try!(pa.open_non_blocking_stream(settings, callback));
+    let mut stream = pa.open_non_blocking_stream(settings, callback)?;
 
-    try!(stream.start());
+    stream.start()?;
 
     println!("Play for {} seconds.", NUM_SECONDS);
     pa.sleep(NUM_SECONDS * 1_000);
 
-    try!(stream.stop());
-    try!(stream.close());
+    stream.stop()?;
+    stream.close()?;
 
     println!("Test finished.");
 
diff --git a/examples/sine.rs b/examples/sine.rs
index 20c7375..ed3f20f 100644
--- a/examples/sine.rs
+++ b/examples/sine.rs
@@ -14,20 +14,20 @@ const SAMPLE_RATE: f64 = 44_100.0;
 const FRAMES_PER_BUFFER: u32 = 64;
 const TABLE_SIZE: usize = 200;
 
-
 fn main() {
     match run() {
-        Ok(_) => {},
+        Ok(_) => {}
         e => {
             eprintln!("Example failed with the following: {:?}", e);
         }
     }
 }
 
-
 fn run() -> Result<(), pa::Error> {
-
-    println!("PortAudio Test: output sine wave. SR = {}, BufSize = {}", SAMPLE_RATE, FRAMES_PER_BUFFER);
+    println!(
+        "PortAudio Test: output sine wave. SR = {}, BufSize = {}",
+        SAMPLE_RATE, FRAMES_PER_BUFFER
+    );
 
     // Initialise sinusoidal wavetable.
     let mut sine = [0.0; TABLE_SIZE];
@@ -37,9 +37,10 @@ fn run() -> Result<(), pa::Error> {
     let mut left_phase = 0;
     let mut right_phase = 0;
 
-    let pa = try!(pa::PortAudio::new());
+    let pa = pa::PortAudio::new()?;
 
-    let mut settings = try!(pa.default_output_stream_settings(CHANNELS, SAMPLE_RATE, FRAMES_PER_BUFFER));
+    let mut settings =
+        pa.default_output_stream_settings(CHANNELS, SAMPLE_RATE, FRAMES_PER_BUFFER)?;
     // we won't output out of range samples so don't bother clipping them.
     settings.flags = pa::stream_flags::CLIP_OFF;
 
@@ -49,26 +50,30 @@ fn run() -> Result<(), pa::Error> {
     let callback = move |pa::OutputStreamCallbackArgs { buffer, frames, .. }| {
         let mut idx = 0;
         for _ in 0..frames {
-            buffer[idx]   = sine[left_phase];
-            buffer[idx+1] = sine[right_phase];
+            buffer[idx] = sine[left_phase];
+            buffer[idx + 1] = sine[right_phase];
             left_phase += 1;
-            if left_phase >= TABLE_SIZE { left_phase -= TABLE_SIZE; }
+            if left_phase >= TABLE_SIZE {
+                left_phase -= TABLE_SIZE;
+            }
             right_phase += 3;
-            if right_phase >= TABLE_SIZE { right_phase -= TABLE_SIZE; }
+            if right_phase >= TABLE_SIZE {
+                right_phase -= TABLE_SIZE;
+            }
             idx += 2;
         }
         pa::Continue
     };
 
-    let mut stream = try!(pa.open_non_blocking_stream(settings, callback));
+    let mut stream = pa.open_non_blocking_stream(settings, callback)?;
 
-    try!(stream.start());
+    stream.start()?;
 
     println!("Play for {} seconds.", NUM_SECONDS);
     pa.sleep(NUM_SECONDS * 1_000);
 
-    try!(stream.stop());
-    try!(stream.close());
+    stream.stop()?;
+    stream.close()?;
 
     println!("Test finished.");
 
diff --git a/src/lib.rs b/src/lib.rs
index 764e230..86d9f1b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -20,30 +20,30 @@
 // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 //! # rust-portaudio
-//! 
+//!
 //! __PortAudio__ bindings for Rust
-//! 
+//!
 //! PortAudio provides a uniform application programming interface (API) across all
 //! supported platforms.  You can think of the PortAudio library as a wrapper that
 //! converts calls to the PortAudio API into calls to platform-specific native audio
 //! APIs. Operating systems often offer more than one native audio API and some APIs
 //! (such as JACK) may be available on multiple target operating systems.
 //! PortAudio supports all the major native audio APIs on each supported platform.
-//! 
+//!
 //! # Installation
-//! 
+//!
 //! rust-portaudio's build script will check to see if you have already installed
 //! PortAudio on your system. If not, it will attempt to automatically download and
 //! install it for you. If this fails, please let us know by posting an issue at [our
 //! github repository] (https://github.com/jeremyletang/rust-portaudio).
-//! 
+//!
 //! If you'd prefer to install it manually, you can download it directly from the website:
 //! [PortAudio](http://www.portaudio.com/download.html).
-//! 
+//!
 //! # Usage
-//! 
+//!
 //! Add rust-portaudio to your project by adding the dependency to your Cargo.toml as follows:
-//! 
+//!
 //! ```toml
 //! [dependencies]
 //! portaudio = "*"
@@ -51,66 +51,45 @@
 
 #![warn(missing_docs)]
 
-#[macro_use] extern crate bitflags;
+#[macro_use]
+extern crate bitflags;
 extern crate libc;
 extern crate num;
 extern crate portaudio_sys as ffi;
 
 use num::FromPrimitive;
-use std::os::raw;
 use std::option::Option;
+use std::os::raw;
 
 pub use error::Error;
+pub use ffi::{
+    PaStreamCallbackResult as StreamCallbackResult, PA_ABORT as Abort, PA_COMPLETE as Complete,
+    PA_CONTINUE as Continue,
+};
 pub use stream::{
-    Available as StreamAvailable,
-    Blocking,
-    callback_flags as stream_callback_flags,
-    CallbackFlags as StreamCallbackFlags,
-    CallbackTimeInfo as StreamCallbackTimeInfo,
-    Duplex,
-    DuplexSettings as DuplexStreamSettings,
-    DuplexCallbackArgs as DuplexStreamCallbackArgs,
-    flags as stream_flags,
-    Flags as StreamFlags,
-    Flow,
-    Info as StreamInfo,
-    Input,
-    InputSettings as InputStreamSettings,
-    InputCallbackArgs as InputStreamCallbackArgs,
-    NonBlocking,
-    Output,
-    OutputSettings as OutputStreamSettings,
-    OutputCallbackArgs as OutputStreamCallbackArgs,
-    Parameters as StreamParameters,
-    Settings as StreamSettings,
-    Stream,
+    callback_flags as stream_callback_flags, flags as stream_flags, Available as StreamAvailable,
+    Blocking, CallbackFlags as StreamCallbackFlags, CallbackTimeInfo as StreamCallbackTimeInfo,
+    Duplex, DuplexCallbackArgs as DuplexStreamCallbackArgs, DuplexSettings as DuplexStreamSettings,
+    Flags as StreamFlags, Flow, Info as StreamInfo, Input,
+    InputCallbackArgs as InputStreamCallbackArgs, InputSettings as InputStreamSettings,
+    NonBlocking, Output, OutputCallbackArgs as OutputStreamCallbackArgs,
+    OutputSettings as OutputStreamSettings, Parameters as StreamParameters,
+    Settings as StreamSettings, Stream,
 };
-pub use ffi::{PaStreamCallbackResult as StreamCallbackResult,
-              PA_CONTINUE as Continue,
-              PA_COMPLETE as Complete,
-              PA_ABORT as Abort};
 pub use types::{
-    DeviceIndex,
-    DeviceInfo,
-    Frames,
-    HostApiIndex,
-    HostApiInfo,
-    HostApiTypeId,
-    HostErrorInfo,
-    SampleFormat,
-    Time,
-    FRAMES_PER_BUFFER_UNSPECIFIED,
+    DeviceIndex, DeviceInfo, Frames, HostApiIndex, HostApiInfo, HostApiTypeId, HostErrorInfo,
+    SampleFormat, Time, FRAMES_PER_BUFFER_UNSPECIFIED,
 };
 
 use std::ptr;
 
-#[macro_use] mod enum_primitive;
+#[macro_use]
+mod enum_primitive;
 pub mod error;
 pub mod ext;
 pub mod stream;
 mod types;
 
-
 /// A type-safe wrapper around the PortAudio API.
 ///
 /// We use a type here instead of pure functions in order to ensure correct intialisation and
@@ -133,9 +112,7 @@ pub struct Life {
     is_terminated: std::sync::Mutex<bool>,
 }
 
-
 impl PortAudio {
-
     /// Construct a **PortAudio** instance.
     ///
     /// This calls PortAudio's `Pa_Initialize` function which initializes internal data structures
@@ -153,10 +130,10 @@ impl PortAudio {
             match error {
                 Error::NoError => {
                     let life = std::sync::Arc::new(Life {
-                        is_terminated: std::sync::Mutex::new(false)
+                        is_terminated: std::sync::Mutex::new(false),
                     });
                     Ok(PortAudio { life: life })
-                },
+                }
                 err => Err(err),
             }
         }
@@ -190,7 +167,7 @@ impl PortAudio {
     /// respective **DeviceInfo**s.
     pub fn devices(&self) -> Result<Devices, Error> {
         Ok(Devices {
-            total: try!(self.device_count()),
+            total: self.device_count()?,
             next: 0,
             port_audio: self,
         })
@@ -259,8 +236,7 @@ impl PortAudio {
         let c_info = unsafe { ffi::Pa_GetDeviceInfo(device.into()) };
         if c_info.is_null() {
             Err(Error::InvalidDevice)
-        }
-        else {
+        } else {
             Ok(DeviceInfo::from_c_info(unsafe { *c_info }))
         }
     }
@@ -284,9 +260,7 @@ impl PortAudio {
     ///
     /// TODO: Determine exactly what errors might occur (PA docs aren't clear on this).
     pub fn host_api_count(&self) -> Result<HostApiIndex, Error> {
-        unsafe {
-            result_from_host_api_index(ffi::Pa_GetHostApiCount())
-        }
+        unsafe { result_from_host_api_index(ffi::Pa_GetHostApiCount()) }
     }
 
     /// Retrieve the index of the default host API.
@@ -299,9 +273,7 @@ impl PortAudio {
     ///
     /// TODO: Determine exactly what errors might occur (PA docs aren't clear on this).
     pub fn default_host_api(&self) -> Result<HostApiIndex, Error> {
-        unsafe {
-            result_from_host_api_index(ffi::Pa_GetDefaultHostApi())
-        }
+        unsafe { result_from_host_api_index(ffi::Pa_GetDefaultHostApi()) }
     }
 
     /// Retrieve a pointer to a structure containing information about a specific host Api.
@@ -332,13 +304,12 @@ impl PortAudio {
     /// an error is encountered.
     ///
     /// TODO: Determine exactly what errors might occur (PA docs aren't clear on this).
-    pub fn host_api_type_id_to_host_api_index(&self, type_id: HostApiTypeId)
-        -> Result<HostApiIndex, Error>
-    {
+    pub fn host_api_type_id_to_host_api_index(
+        &self,
+        type_id: HostApiTypeId,
+    ) -> Result<HostApiIndex, Error> {
         let id = FromPrimitive::from_i32(type_id as i32).unwrap();
-        unsafe {
-            result_from_host_api_index(ffi::Pa_HostApiTypeIdToHostApiIndex(id))
-        }
+        unsafe { result_from_host_api_index(ffi::Pa_HostApiTypeIdToHostApiIndex(id)) }
     }
 
     /// Convert a host-API-specific device index to standard PortAudio device index.
@@ -356,14 +327,13 @@ impl PortAudio {
     /// or an `Error` if an error is encountered.
     ///
     /// TODO: Determine exactly what errors might occur (PA docs aren't clear on this).
-    pub fn api_device_index_to_device_index(&self,
-                                            host_api: HostApiIndex,
-                                            host_api_device_index: i32)
-                                            -> Result<DeviceIndex, Error>
-    {
-        let result = unsafe {
-            ffi::Pa_HostApiDeviceIndexToDeviceIndex(host_api, host_api_device_index)
-        };
+    pub fn api_device_index_to_device_index(
+        &self,
+        host_api: HostApiIndex,
+        host_api_device_index: i32,
+    ) -> Result<DeviceIndex, Error> {
+        let result =
+            unsafe { ffi::Pa_HostApiDeviceIndexToDeviceIndex(host_api, host_api_device_index) };
         match result {
             idx if idx >= 0 => Ok(DeviceIndex(idx as u32)),
             err => Err(::num::FromPrimitive::from_i32(err).unwrap()),
@@ -377,9 +347,13 @@ impl PortAudio {
     ///
     /// Returns `Ok(())` if the format is supported, and an `Err(Error)` indicating why the format
     /// is not supported otherwise.
-    pub fn is_input_format_supported<I>(&self, params: StreamParameters<I>, sample_rate: f64)
-        -> Result<(), Error>
-        where I: Sample,
+    pub fn is_input_format_supported<I>(
+        &self,
+        params: StreamParameters<I>,
+        sample_rate: f64,
+    ) -> Result<(), Error>
+    where
+        I: Sample,
     {
         is_format_supported(Some(params.into()), None, sample_rate)
     }
@@ -391,9 +365,13 @@ impl PortAudio {
     ///
     /// Returns `Ok(())` if the format is supported, and an `Err(Error)` indicating why the format
     /// is not supported otherwise.
-    pub fn is_output_format_supported<O>(&self, params: StreamParameters<O>, sample_rate: f64)
-        -> Result<(), Error>
-        where O: Sample,
+    pub fn is_output_format_supported<O>(
+        &self,
+        params: StreamParameters<O>,
+        sample_rate: f64,
+    ) -> Result<(), Error>
+    where
+        O: Sample,
     {
         is_format_supported(None, Some(params.into()), sample_rate)
     }
@@ -405,13 +383,15 @@ impl PortAudio {
     ///
     /// Returns `Ok(())` if the format is supported, and an `Err(Error)` indicating why the format
     /// is not supported otherwise.
-    pub fn is_duplex_format_supported<I, O>(&self,
-                                            in_params: StreamParameters<I>,
-                                            out_params: StreamParameters<O>,
-                                            sample_rate: f64)
-        -> Result<(), Error>
-        where I: Sample,
-              O: Sample,
+    pub fn is_duplex_format_supported<I, O>(
+        &self,
+        in_params: StreamParameters<I>,
+        out_params: StreamParameters<O>,
+        sample_rate: f64,
+    ) -> Result<(), Error>
+    where
+        I: Sample,
+        O: Sample,
     {
         is_format_supported(Some(in_params.into()), Some(out_params.into()), sample_rate)
     }
@@ -427,10 +407,13 @@ impl PortAudio {
     /// respectively.
     ///
     /// The returned **Stream** is inactive (stopped).
-    pub fn open_blocking_stream<S>(&self, settings: S)
-        -> Result<Stream<Blocking<<S::Flow as Flow>::Buffer>, S::Flow>, Error>
-        where S: StreamSettings,
-              S::Flow: Flow,
+    pub fn open_blocking_stream<S>(
+        &self,
+        settings: S,
+    ) -> Result<Stream<Blocking<<S::Flow as Flow>::Buffer>, S::Flow>, Error>
+    where
+        S: StreamSettings,
+        S::Flow: Flow,
     {
         Stream::<Blocking<<S::Flow as Flow>::Buffer>, S::Flow>::open(self.life.clone(), settings)
     }
@@ -469,11 +452,15 @@ impl PortAudio {
     /// irrespective of its return value.
     ///
     /// The returned **Stream** is inactive (stopped).
-    pub fn open_non_blocking_stream<S, C>(&self, settings: S, callback: C)
-        -> Result<Stream<NonBlocking, S::Flow>, Error>
-        where S: StreamSettings,
-              S::Flow: Flow,
-              C: FnMut(<S::Flow as Flow>::CallbackArgs) -> ffi::PaStreamCallbackResult + 'static,
+    pub fn open_non_blocking_stream<S, C>(
+        &self,
+        settings: S,
+        callback: C,
+    ) -> Result<Stream<NonBlocking, S::Flow>, Error>
+    where
+        S: StreamSettings,
+        S::Flow: Flow,
+        C: FnMut(<S::Flow as Flow>::CallbackArgs) -> ffi::PaStreamCallbackResult + 'static,
     {
         Stream::<NonBlocking, S::Flow>::open(self.life.clone(), settings, callback)
     }
@@ -483,13 +470,19 @@ impl PortAudio {
     /// The device used will be the default input device for the default Host API.
     ///
     /// The produced **Parameters** will assume interleaved buffered audio data.
-    pub fn default_input_stream_params<I>(&self, channels: i32)
-        -> Result<StreamParameters<I>, Error>
-    {
+    pub fn default_input_stream_params<I>(
+        &self,
+        channels: i32,
+    ) -> Result<StreamParameters<I>, Error> {
         const INTERLEAVED: bool = true;
-        let device = try!(self.default_input_device());
-        let latency = try!(self.device_info(device)).default_low_input_latency;
-        Ok(StreamParameters::new(device, channels, INTERLEAVED, latency))
+        let device = self.default_input_device()?;
+        let latency = self.device_info(device)?.default_low_input_latency;
+        Ok(StreamParameters::new(
+            device,
+            channels,
+            INTERLEAVED,
+            latency,
+        ))
     }
 
     /// Produce the default **StreamParameters** for an **Output** **Stream**.
@@ -497,13 +490,19 @@ impl PortAudio {
     /// The device used will be the default output device for the default Host API.
     ///
     /// The produced **Parameters** will assume interleaved buffered audio data.
-    pub fn default_output_stream_params<O>(&self, channels: i32)
-        -> Result<StreamParameters<O>, Error>
-    {
+    pub fn default_output_stream_params<O>(
+        &self,
+        channels: i32,
+    ) -> Result<StreamParameters<O>, Error> {
         const INTERLEAVED: bool = true;
-        let device = try!(self.default_output_device());
-        let latency = try!(self.device_info(device)).default_low_output_latency;
-        Ok(StreamParameters::new(device, channels, INTERLEAVED, latency))
+        let device = self.default_output_device()?;
+        let latency = self.device_info(device)?.default_low_output_latency;
+        Ok(StreamParameters::new(
+            device,
+            channels,
+            INTERLEAVED,
+            latency,
+        ))
     }
 
     /// Produce the default **InputStreamSettings** with the given number of channels, sample_rate
@@ -512,14 +511,18 @@ impl PortAudio {
     /// The device used will be the default input device for the default Host API.
     ///
     /// The produced settings will assume interleaved buffered audio data.
-    pub fn default_input_stream_settings<I>(&self,
-                                            channels: i32,
-                                            sample_rate: f64,
-                                            frames_per_buffer: u32)
-                                            -> Result<InputStreamSettings<I>, Error>
-    {
-        let params = try!(self.default_input_stream_params(channels));
-        Ok(InputStreamSettings::new(params, sample_rate, frames_per_buffer))
+    pub fn default_input_stream_settings<I>(
+        &self,
+        channels: i32,
+        sample_rate: f64,
+        frames_per_buffer: u32,
+    ) -> Result<InputStreamSettings<I>, Error> {
+        let params = self.default_input_stream_params(channels)?;
+        Ok(InputStreamSettings::new(
+            params,
+            sample_rate,
+            frames_per_buffer,
+        ))
     }
 
     /// Produce the default **OutputStreamSettings** with the given number of channels, sample_rate
@@ -528,14 +531,18 @@ impl PortAudio {
     /// The device used will be the default output device for the default Host API.
     ///
     /// The produced settings will assume interleaved buffered audio data.
-    pub fn default_output_stream_settings<O>(&self,
-                                             channels: i32,
-                                             sample_rate: f64,
-                                             frames_per_buffer: u32)
-                                             -> Result<OutputStreamSettings<O>, Error>
-    {
-        let params = try!(self.default_output_stream_params(channels));
-        Ok(OutputStreamSettings::new(params, sample_rate, frames_per_buffer))
+    pub fn default_output_stream_settings<O>(
+        &self,
+        channels: i32,
+        sample_rate: f64,
+        frames_per_buffer: u32,
+    ) -> Result<OutputStreamSettings<O>, Error> {
+        let params = self.default_output_stream_params(channels)?;
+        Ok(OutputStreamSettings::new(
+            params,
+            sample_rate,
+            frames_per_buffer,
+        ))
     }
 
     /// Produce the default **DuplexStreamSettings** with the given number of channels, sample_rate
@@ -544,16 +551,21 @@ impl PortAudio {
     /// The devices used will be the default input and output devices for the default Host API.
     ///
     /// The produced settings will assume interleaved buffered audio data.
-    pub fn default_duplex_stream_settings<I, O>(&self,
-                                                in_channels: i32,
-                                                out_channels: i32,
-                                                sample_rate: f64,
-                                                frames_per_buffer: u32)
-                                                -> Result<DuplexStreamSettings<I, O>, Error>
-    {
-        let in_params = try!(self.default_input_stream_params(in_channels));
-        let out_params = try!(self.default_output_stream_params(out_channels));
-        Ok(DuplexStreamSettings::new(in_params, out_params, sample_rate, frames_per_buffer))
+    pub fn default_duplex_stream_settings<I, O>(
+        &self,
+        in_channels: i32,
+        out_channels: i32,
+        sample_rate: f64,
+        frames_per_buffer: u32,
+    ) -> Result<DuplexStreamSettings<I, O>, Error> {
+        let in_params = self.default_input_stream_params(in_channels)?;
+        let out_params = self.default_output_stream_params(out_channels)?;
+        Ok(DuplexStreamSettings::new(
+            in_params,
+            out_params,
+            sample_rate,
+            frames_per_buffer,
+        ))
     }
 
     /// Put the caller to sleep for at least 'msec' milliseconds.
@@ -565,9 +577,7 @@ impl PortAudio {
     /// The function may sleep longer than requested so don't rely on this for accurate musical
     /// timing.
     pub fn sleep(&self, m_sec: i32) -> () {
-        unsafe {
-            ffi::Pa_Sleep(m_sec as raw::c_long)
-        }
+        unsafe { ffi::Pa_Sleep(m_sec as raw::c_long) }
     }
 
     /// Return information about the last host error encountered.
@@ -586,10 +596,8 @@ impl PortAudio {
         let c_error = unsafe { ffi::Pa_GetLastHostErrorInfo() };
         HostErrorInfo::from_c_error_info(unsafe { *c_error })
     }
-
 }
 
-
 impl Drop for Life {
     fn drop(&mut self) {
         if !*self.is_terminated.lock().unwrap() {
@@ -598,24 +606,18 @@ impl Drop for Life {
     }
 }
 
-
 /// Retrieve the release number of the currently running PortAudio build.
 pub fn version() -> i32 {
-    unsafe {
-        ffi::Pa_GetVersion()
-    }
+    unsafe { ffi::Pa_GetVersion() }
 }
 
 /// Retrieve a textual description of the current PortAudio build.
 ///
 /// FIXME: This should return a `&'static str`, not a `String`.
 pub fn version_text() -> Result<&'static str, ::std::str::Utf8Error> {
-    unsafe {
-        ffi::c_str_to_str(ffi::Pa_GetVersionText())
-    }
+    unsafe { ffi::c_str_to_str(ffi::Pa_GetVersionText()) }
 }
 
-
 /// This is used by the **PortAudio::terminate** method.
 ///
 /// Library termination function - call this when finished using PortAudio.
@@ -661,20 +663,26 @@ fn terminate() -> Result<(), Error> {
 /// Return Ok(()) if the format is supported, and an Error indicating why the format is not
 /// supported otherwise. The constant PaFormatIsSupported is provided to compare with the return
 /// value for success.
-fn is_format_supported(maybe_input_parameters: Option<ffi::PaStreamParameters>,
-                       maybe_output_parameters: Option<ffi::PaStreamParameters>,
-                       sample_rate : f64) -> Result<(), Error>
-{
-    let c_input = maybe_input_parameters.as_ref().map(|input| input as *const _);
-    let c_output = maybe_output_parameters.as_ref().map(|output| output as *const _);
+fn is_format_supported(
+    maybe_input_parameters: Option<ffi::PaStreamParameters>,
+    maybe_output_parameters: Option<ffi::PaStreamParameters>,
+    sample_rate: f64,
+) -> Result<(), Error> {
+    let c_input = maybe_input_parameters
+        .as_ref()
+        .map(|input| input as *const _);
+    let c_output = maybe_output_parameters
+        .as_ref()
+        .map(|output| output as *const _);
     if c_input.is_none() && c_output.is_none() {
         Err(Error::InvalidDevice)
     } else {
         unsafe {
-            let error_code =
-                ffi::Pa_IsFormatSupported(c_input.unwrap_or(ptr::null()),
-                                          c_output.unwrap_or(ptr::null()),
-                                          sample_rate as raw::c_double);
+            let error_code = ffi::Pa_IsFormatSupported(
+                c_input.unwrap_or(ptr::null()),
+                c_output.unwrap_or(ptr::null()),
+                sample_rate as raw::c_double,
+            );
             let error = FromPrimitive::from_i32(error_code).unwrap();
             match error {
                 Error::NoError => Ok(()),
@@ -684,7 +692,6 @@ fn is_format_supported(maybe_input_parameters: Option<ffi::PaStreamParameters>,
     }
 }
 
-
 /// An iterator yielding the **DeviceIndex** for each available device along with their respective
 /// **DeviceInfo**s.
 pub struct Devices<'a> {
@@ -693,7 +700,6 @@ pub struct Devices<'a> {
     port_audio: &'a PortAudio,
 }
 
-
 /// An iterator yielding the **HostApiIndex** for each available API along with their respective
 /// **HostApiInfo**s.
 #[derive(Clone, Debug)]
@@ -703,7 +709,6 @@ pub struct HostApis<'a> {
     port_audio: &'a PortAudio,
 }
 
-
 impl<'a> Iterator for Devices<'a> {
     type Item = Result<(DeviceIndex, DeviceInfo<'a>), Error>;
     fn next(&mut self) -> Option<Self::Item> {
@@ -716,7 +721,6 @@ impl<'a> Iterator for Devices<'a> {
     }
 }
 
-
 impl<'a> Iterator for HostApis<'a> {
     type Item = (HostApiIndex, HostApiInfo<'a>);
     fn next(&mut self) -> Option<Self::Item> {
@@ -731,7 +735,6 @@ impl<'a> Iterator for HostApis<'a> {
     }
 }
 
-
 fn result_from_host_api_index(idx: ffi::PaHostApiIndex) -> Result<HostApiIndex, Error> {
     match idx {
         idx if idx >= 0 => Ok(idx),
@@ -739,7 +742,6 @@ fn result_from_host_api_index(idx: ffi::PaHostApiIndex) -> Result<HostApiIndex,
     }
 }
 
-
 /// Retrieve the size of a given sample format in bytes.
 ///
 /// Return the size in bytes of a single sample in the specified format,
@@ -753,15 +755,24 @@ pub fn get_sample_size(format: SampleFormat) -> Result<u8, Error> {
     }
 }
 
-
 mod private {
-    use num::{FromPrimitive, ToPrimitive};
-    use std::ops::{Add, Sub, Mul, Div};
     use super::types::SampleFormat;
+    use num::{FromPrimitive, ToPrimitive};
+    use std::ops::{Add, Div, Mul, Sub};
 
     /// internal private trait for Sample format management
-    pub trait SamplePrivate: ::std::default::Default + Copy + Clone + ::std::fmt::Debug
-                             + ToPrimitive + FromPrimitive + Add + Sub + Mul + Div {
+    pub trait SamplePrivate:
+        ::std::default::Default
+        + Copy
+        + Clone
+        + ::std::fmt::Debug
+        + ToPrimitive
+        + FromPrimitive
+        + Add
+        + Sub
+        + Mul
+        + Div
+    {
         /// return the size of a sample format
         fn size<S: SamplePrivate>() -> usize {
             ::std::mem::size_of::<S>()
@@ -772,29 +783,41 @@ mod private {
 }
 
 impl private::SamplePrivate for f32 {
-    fn to_sample_format() -> SampleFormat { SampleFormat::F32 }
+    fn to_sample_format() -> SampleFormat {
+        SampleFormat::F32
+    }
 }
 
 impl private::SamplePrivate for i32 {
-    fn to_sample_format() -> SampleFormat { SampleFormat::I32 }
+    fn to_sample_format() -> SampleFormat {
+        SampleFormat::I32
+    }
 }
 
 impl private::SamplePrivate for i16 {
-    fn to_sample_format() -> SampleFormat { SampleFormat::I16 }
+    fn to_sample_format() -> SampleFormat {
+        SampleFormat::I16
+    }
 }
 
 impl private::SamplePrivate for i8 {
-    fn to_sample_format() -> SampleFormat { SampleFormat::I8 }
+    fn to_sample_format() -> SampleFormat {
+        SampleFormat::I8
+    }
 }
 
 impl private::SamplePrivate for u8 {
-    fn to_sample_format() -> SampleFormat { SampleFormat::U8 }
+    fn to_sample_format() -> SampleFormat {
+        SampleFormat::U8
+    }
 }
 
 /// public trait to constraint pa::Stream for specific types
 pub trait Sample: private::SamplePrivate {
     /// Retrieve the SampleFormat variant associated with the type.
-    fn sample_format() -> SampleFormat { Self::to_sample_format() }
+    fn sample_format() -> SampleFormat {
+        Self::to_sample_format()
+    }
 }
 
 impl Sample for f32 {}


Test patch: