From 95dc336b652802870e871b4484a8a169449a16a9 Mon Sep 17 00:00:00 2001 From: Luis de Bethencourt Date: Sun, 22 Oct 2017 14:01:29 +0100 Subject: [PATCH] Use while let When destructuring a single pattern in a loop it is nicer to use while let. Fixes https://github.com/sdroege/gstreamer-rs/pull/46 Fixes https://github.com/sdroege/gstreamer-rs/issues/45 --- tutorials/src/bin/basic-tutorial-6.rs | 63 ++++++++++++--------------- 1 file changed, 28 insertions(+), 35 deletions(-) diff --git a/tutorials/src/bin/basic-tutorial-6.rs b/tutorials/src/bin/basic-tutorial-6.rs index 297bb979b..7dda01525 100644 --- a/tutorials/src/bin/basic-tutorial-6.rs +++ b/tutorials/src/bin/basic-tutorial-6.rs @@ -119,42 +119,35 @@ fn main() { // Wait until error, EOS or State Change let bus = pipeline.get_bus().unwrap(); - loop { - let msg = bus.timed_pop(gst::CLOCK_TIME_NONE); - - match msg { - Some(msg) => { - match msg.view() { - MessageView::Error(err) => { - println!( - "Error received from element {}: {} ({:?})", - msg.get_src().get_path_string(), - err.get_error(), - err.get_debug() - ); - break; - } - MessageView::Eos(..) => { - println!("End-Of-Stream reached."); - break; - } - MessageView::StateChanged(state) => - // We are only interested in state-changed messages from the pipeline - if msg.get_src() == pipeline { - let new_state = state.get_current(); - let old_state = state.get_old(); - - println!( - "Pipeline state changed from {:?} to {:?}", - old_state, - new_state - ); - print_pad_capabilities(&sink, "sink"); - }, - _ => (), - } + while let Some(msg) = bus.timed_pop(gst::CLOCK_TIME_NONE) { + match msg.view() { + MessageView::Error(err) => { + println!( + "Error received from element {}: {} ({:?})", + msg.get_src().get_path_string(), + err.get_error(), + err.get_debug() + ); + break; } - None => (), + MessageView::Eos(..) => { + println!("End-Of-Stream reached."); + break; + } + MessageView::StateChanged(state) => + // We are only interested in state-changed messages from the pipeline + if msg.get_src() == pipeline { + let new_state = state.get_current(); + let old_state = state.get_old(); + + println!( + "Pipeline state changed from {:?} to {:?}", + old_state, + new_state + ); + print_pad_capabilities(&sink, "sink"); + }, + _ => (), } }