Casting Between Element Types in Rust
In rust, what is the best-practice for casting between element types? Is it best to use an unsafe transmute or is there a better way?
In this example, parse_launch() returns a new Element, but I know it's a Pipeline, to which I need access as that type. Within the pipeline, the Element named "sink" is always an AppSink, hence......
let el = gst::parse_launch(pipeline_string)?;
let pipeline = unsafe { std::mem::transmute::<gst::Element, gst::Pipeline>(el) };
let sink = pipeline.by_name("sink");
if let Some(sink) = sink {
log_info("sink found");
let app_sink = unsafe { std::mem::transmute::<gst::Element, gst_app::AppSink>(sink)};
// do stuff with the AppSink
}
else {
log_info("No sink found");
}
This works, but seems like a code-smell...... is there a better/cleaner way?.... e.g.
let el = gst::parse_launch(pipeline_string)?;
let pipeline = el.downcast::<gst::Pipeline>().unwrap();
Thanks