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
This commit is contained in:
Luis de Bethencourt 2017-10-22 14:01:29 +01:00 committed by Sebastian Dröge
parent 342d89dd44
commit 95dc336b65

View file

@ -119,42 +119,35 @@ fn main() {
// Wait until error, EOS or State Change // Wait until error, EOS or State Change
let bus = pipeline.get_bus().unwrap(); let bus = pipeline.get_bus().unwrap();
loop { while let Some(msg) = bus.timed_pop(gst::CLOCK_TIME_NONE) {
let msg = bus.timed_pop(gst::CLOCK_TIME_NONE); match msg.view() {
MessageView::Error(err) => {
match msg { println!(
Some(msg) => { "Error received from element {}: {} ({:?})",
match msg.view() { msg.get_src().get_path_string(),
MessageView::Error(err) => { err.get_error(),
println!( err.get_debug()
"Error received from element {}: {} ({:?})", );
msg.get_src().get_path_string(), break;
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");
},
_ => (),
}
} }
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");
},
_ => (),
} }
} }