event::Caps::caps does not use the EventRef's lifetime
event::Caps::caps
no longer returns a CapsRef
copying the EventRef
's lifetime, making for worse code.
The following code compiles using 0.17, but not 0.18:
use gstreamer::{self as gst, prelude::*};
fn probe_func(_pad: &gst::Pad, info: &mut gst::PadProbeInfo) -> gst::PadProbeReturn {
let caps = match &info.data {
Some(gst::PadProbeData::Event(e)) => match e.view() {
gst::EventView::Caps(c) => c.caps(),
_ => return gst::PadProbeReturn::Ok,
},
_ => unreachable!(),
};
println!("{}", caps);
gst::PadProbeReturn::Ok
}
fn main() {
gst::init().unwrap();
let pad = gst::Pad::new(None, gst::PadDirection::Src);
pad.add_probe(gst::PadProbeType::EVENT_DOWNSTREAM, probe_func);
}
0.18 requires either taking a ref of the caps:
let caps = match &info.data {
Some(gst::PadProbeData::Event(e)) => match e.view() {
gst::EventView::Caps(c) => c.caps_owned(), // 💡 Returns an owned Caps
_ => return gst::PadProbeReturn::Ok,
},
_ => unreachable!(),
};
println!("{}", caps);
Or storing the event::Caps
first:
let caps = match &info.data {
Some(gst::PadProbeData::Event(e)) => match e.view() {
gst::EventView::Caps(c) => c, // 💡 Extract the event::Caps
_ => return gst::PadProbeReturn::Ok,
},
_ => unreachable!(),
};
let caps = caps.caps(); // 💡 Extract the CapsRef
println!("{}", caps);