Use Option<&T> instead of &Option<T> everywhere

Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/issues/203
This commit is contained in:
Sebastian Dröge 2019-05-22 23:27:13 +03:00
parent 32d7f42d67
commit a986914bad
6 changed files with 55 additions and 55 deletions

View file

@ -53,11 +53,11 @@ pub fn type_find_helper_for_extension<P: IsA<gst::Object>>(obj: Option<&P>, exte
}
}
//pub fn type_find_helper_get_range<P: IsA<gst::Object>, Q: IsA<gst::Object>, R: FnMut(&gst::Object, &Option<gst::Object>, u64, u32, &gst::Buffer) -> gst::FlowReturn>(obj: &P, parent: Option<&Q>, func: R, size: u64, extension: Option<&str>) -> (Option<gst::Caps>, gst::TypeFindProbability) {
//pub fn type_find_helper_get_range<P: IsA<gst::Object>, Q: IsA<gst::Object>, R: FnMut(&gst::Object, Option<&gst::Object>, u64, u32, &gst::Buffer) -> gst::FlowReturn>(obj: &P, parent: Option<&Q>, func: R, size: u64, extension: Option<&str>) -> (Option<gst::Caps>, gst::TypeFindProbability) {
// unsafe { TODO: call gst_base_sys:gst_type_find_helper_get_range() }
//}
//#[cfg(any(feature = "v1_14_3", feature = "dox"))]
//pub fn type_find_helper_get_range_full<P: IsA<gst::Object>, Q: IsA<gst::Object>, R: FnMut(&gst::Object, &Option<gst::Object>, u64, u32, &gst::Buffer) -> gst::FlowReturn>(obj: &P, parent: Option<&Q>, func: R, size: u64, extension: Option<&str>) -> (gst::FlowReturn, gst::Caps, gst::TypeFindProbability) {
//pub fn type_find_helper_get_range_full<P: IsA<gst::Object>, Q: IsA<gst::Object>, R: FnMut(&gst::Object, Option<&gst::Object>, u64, u32, &gst::Buffer) -> gst::FlowReturn>(obj: &P, parent: Option<&Q>, func: R, size: u64, extension: Option<&str>) -> (gst::FlowReturn, gst::Caps, gst::TypeFindProbability) {
// unsafe { TODO: call gst_base_sys:gst_type_find_helper_get_range_full() }
//}

View file

@ -83,7 +83,7 @@ impl Discoverer {
}
}
pub fn connect_discovered<F: Fn(&Discoverer, &DiscovererInfo, &Option<Error>) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
pub fn connect_discovered<F: Fn(&Discoverer, &DiscovererInfo, Option<&Error>) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(self.as_ptr() as *mut _, b"discovered\0".as_ptr() as *const _,
@ -128,9 +128,9 @@ impl Discoverer {
unsafe impl Send for Discoverer {}
unsafe impl Sync for Discoverer {}
unsafe extern "C" fn discovered_trampoline<F: Fn(&Discoverer, &DiscovererInfo, &Option<Error>) + Send + Sync + 'static>(this: *mut gst_pbutils_sys::GstDiscoverer, info: *mut gst_pbutils_sys::GstDiscovererInfo, error: *mut glib_sys::GError, f: glib_sys::gpointer) {
unsafe extern "C" fn discovered_trampoline<F: Fn(&Discoverer, &DiscovererInfo, Option<&Error>) + Send + Sync + 'static>(this: *mut gst_pbutils_sys::GstDiscoverer, info: *mut gst_pbutils_sys::GstDiscovererInfo, error: *mut glib_sys::GError, f: glib_sys::gpointer) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this), &from_glib_borrow(info), &from_glib_borrow(error))
f(&from_glib_borrow(this), &from_glib_borrow(info), Option::<Error>::from_glib_borrow(error).as_ref())
}
unsafe extern "C" fn finished_trampoline<F: Fn(&Discoverer) + Send + Sync + 'static>(this: *mut gst_pbutils_sys::GstDiscoverer, f: glib_sys::gpointer) {

View file

@ -166,65 +166,65 @@ pub trait PadExtManual: 'static {
fn set_activate_function<F>(&self, func: F)
where
F: Fn(&Self, &Option<::Object>) -> Result<(), LoggableError> + Send + Sync + 'static;
F: Fn(&Self, Option<&::Object>) -> Result<(), LoggableError> + Send + Sync + 'static;
fn set_activatemode_function<F>(&self, func: F)
where
F: Fn(&Self, &Option<::Object>, ::PadMode, bool) -> Result<(), LoggableError>
F: Fn(&Self, Option<&::Object>, ::PadMode, bool) -> Result<(), LoggableError>
+ Send
+ Sync
+ 'static;
fn set_chain_function<F>(&self, func: F)
where
F: Fn(&Self, &Option<::Object>, ::Buffer) -> Result<FlowSuccess, FlowError>
F: Fn(&Self, Option<&::Object>, ::Buffer) -> Result<FlowSuccess, FlowError>
+ Send
+ Sync
+ 'static;
fn set_chain_list_function<F>(&self, func: F)
where
F: Fn(&Self, &Option<::Object>, ::BufferList) -> Result<FlowSuccess, FlowError>
F: Fn(&Self, Option<&::Object>, ::BufferList) -> Result<FlowSuccess, FlowError>
+ Send
+ Sync
+ 'static;
fn set_event_function<F>(&self, func: F)
where
F: Fn(&Self, &Option<::Object>, ::Event) -> bool + Send + Sync + 'static;
F: Fn(&Self, Option<&::Object>, ::Event) -> bool + Send + Sync + 'static;
fn set_event_full_function<F>(&self, func: F)
where
F: Fn(&Self, &Option<::Object>, ::Event) -> Result<FlowSuccess, FlowError>
F: Fn(&Self, Option<&::Object>, ::Event) -> Result<FlowSuccess, FlowError>
+ Send
+ Sync
+ 'static;
fn set_getrange_function<F>(&self, func: F)
where
F: Fn(&Self, &Option<::Object>, u64, u32) -> Result<::Buffer, ::FlowError>
F: Fn(&Self, Option<&::Object>, u64, u32) -> Result<::Buffer, ::FlowError>
+ Send
+ Sync
+ 'static;
fn set_iterate_internal_links_function<F>(&self, func: F)
where
F: Fn(&Self, &Option<::Object>) -> ::Iterator<Pad> + Send + Sync + 'static;
F: Fn(&Self, Option<&::Object>) -> ::Iterator<Pad> + Send + Sync + 'static;
fn set_link_function<F>(&self, func: F)
where
F: Fn(&Self, &Option<::Object>, &Pad) -> Result<::PadLinkSuccess, ::PadLinkError>
F: Fn(&Self, Option<&::Object>, &Pad) -> Result<::PadLinkSuccess, ::PadLinkError>
+ Send
+ Sync
+ 'static;
fn set_query_function<F>(&self, func: F)
where
F: Fn(&Self, &Option<::Object>, &mut ::QueryRef) -> bool + Send + Sync + 'static;
F: Fn(&Self, Option<&::Object>, &mut ::QueryRef) -> bool + Send + Sync + 'static;
fn set_unlink_function<F>(&self, func: F)
where
F: Fn(&Self, &Option<::Object>) + Send + Sync + 'static;
F: Fn(&Self, Option<&::Object>) + Send + Sync + 'static;
fn start_task<F: FnMut() + Send + 'static>(&self, func: F) -> Result<(), glib::BoolError>;
@ -522,7 +522,7 @@ impl<O: IsA<Pad>> PadExtManual for O {
fn set_activate_function<F>(&self, func: F)
where
F: Fn(&Self, &Option<::Object>) -> Result<(), LoggableError> + Send + Sync + 'static,
F: Fn(&Self, Option<&::Object>) -> Result<(), LoggableError> + Send + Sync + 'static,
{
#[allow(clippy::type_complexity)]
unsafe {
@ -538,7 +538,7 @@ impl<O: IsA<Pad>> PadExtManual for O {
fn set_activatemode_function<F>(&self, func: F)
where
F: Fn(&Self, &Option<::Object>, ::PadMode, bool) -> Result<(), LoggableError>
F: Fn(&Self, Option<&::Object>, ::PadMode, bool) -> Result<(), LoggableError>
+ Send
+ Sync
+ 'static,
@ -557,7 +557,7 @@ impl<O: IsA<Pad>> PadExtManual for O {
fn set_chain_function<F>(&self, func: F)
where
F: Fn(&Self, &Option<::Object>, ::Buffer) -> Result<FlowSuccess, FlowError>
F: Fn(&Self, Option<&::Object>, ::Buffer) -> Result<FlowSuccess, FlowError>
+ Send
+ Sync
+ 'static,
@ -575,7 +575,7 @@ impl<O: IsA<Pad>> PadExtManual for O {
fn set_chain_list_function<F>(&self, func: F)
where
F: Fn(&Self, &Option<::Object>, ::BufferList) -> Result<FlowSuccess, FlowError>
F: Fn(&Self, Option<&::Object>, ::BufferList) -> Result<FlowSuccess, FlowError>
+ Send
+ Sync
+ 'static,
@ -593,7 +593,7 @@ impl<O: IsA<Pad>> PadExtManual for O {
fn set_event_function<F>(&self, func: F)
where
F: Fn(&Self, &Option<::Object>, ::Event) -> bool + Send + Sync + 'static,
F: Fn(&Self, Option<&::Object>, ::Event) -> bool + Send + Sync + 'static,
{
unsafe {
let func_box: Box<F> = Box::new(func);
@ -608,7 +608,7 @@ impl<O: IsA<Pad>> PadExtManual for O {
fn set_event_full_function<F>(&self, func: F)
where
F: Fn(&Self, &Option<::Object>, ::Event) -> Result<FlowSuccess, FlowError>
F: Fn(&Self, Option<&::Object>, ::Event) -> Result<FlowSuccess, FlowError>
+ Send
+ Sync
+ 'static,
@ -626,7 +626,7 @@ impl<O: IsA<Pad>> PadExtManual for O {
fn set_getrange_function<F>(&self, func: F)
where
F: Fn(&Self, &Option<::Object>, u64, u32) -> Result<::Buffer, FlowError>
F: Fn(&Self, Option<&::Object>, u64, u32) -> Result<::Buffer, FlowError>
+ Send
+ Sync
+ 'static,
@ -644,7 +644,7 @@ impl<O: IsA<Pad>> PadExtManual for O {
fn set_iterate_internal_links_function<F>(&self, func: F)
where
F: Fn(&Self, &Option<::Object>) -> ::Iterator<Pad> + Send + Sync + 'static,
F: Fn(&Self, Option<&::Object>) -> ::Iterator<Pad> + Send + Sync + 'static,
{
unsafe {
let func_box: Box<F> = Box::new(func);
@ -659,7 +659,7 @@ impl<O: IsA<Pad>> PadExtManual for O {
fn set_link_function<F>(&self, func: F)
where
F: Fn(&Self, &Option<::Object>, &Pad) -> Result<::PadLinkSuccess, ::PadLinkError>
F: Fn(&Self, Option<&::Object>, &Pad) -> Result<::PadLinkSuccess, ::PadLinkError>
+ Send
+ Sync
+ 'static,
@ -677,7 +677,7 @@ impl<O: IsA<Pad>> PadExtManual for O {
fn set_query_function<F>(&self, func: F)
where
F: Fn(&Self, &Option<::Object>, &mut ::QueryRef) -> bool + Send + Sync + 'static,
F: Fn(&Self, Option<&::Object>, &mut ::QueryRef) -> bool + Send + Sync + 'static,
{
unsafe {
let func_box: Box<F> = Box::new(func);
@ -692,7 +692,7 @@ impl<O: IsA<Pad>> PadExtManual for O {
fn set_unlink_function<F>(&self, func: F)
where
F: Fn(&Self, &Option<::Object>) + Send + Sync + 'static,
F: Fn(&Self, Option<&::Object>) + Send + Sync + 'static,
{
unsafe {
let func_box: Box<F> = Box::new(func);
@ -1139,7 +1139,7 @@ where
unsafe extern "C" fn trampoline_activate_function<
T,
F: Fn(&T, &Option<::Object>) -> Result<(), LoggableError> + Send + Sync + 'static,
F: Fn(&T, Option<&::Object>) -> Result<(), LoggableError> + Send + Sync + 'static,
>(
pad: *mut gst_sys::GstPad,
parent: *mut gst_sys::GstObject,
@ -1151,7 +1151,7 @@ where
match func(
&Pad::from_glib_borrow(pad).unsafe_cast(),
&from_glib_borrow(parent),
Option::<::Object>::from_glib_borrow(parent).as_ref(),
) {
Ok(()) => true,
Err(err) => {
@ -1164,7 +1164,7 @@ where
unsafe extern "C" fn trampoline_activatemode_function<
T,
F: Fn(&T, &Option<::Object>, ::PadMode, bool) -> Result<(), LoggableError> + Send + Sync + 'static,
F: Fn(&T, Option<&::Object>, ::PadMode, bool) -> Result<(), LoggableError> + Send + Sync + 'static,
>(
pad: *mut gst_sys::GstPad,
parent: *mut gst_sys::GstObject,
@ -1178,7 +1178,7 @@ where
match func(
&&Pad::from_glib_borrow(pad).unsafe_cast(),
&from_glib_borrow(parent),
Option::<::Object>::from_glib_borrow(parent).as_ref(),
from_glib(mode),
from_glib(active),
) {
@ -1193,7 +1193,7 @@ where
unsafe extern "C" fn trampoline_chain_function<
T,
F: Fn(&T, &Option<::Object>, ::Buffer) -> Result<FlowSuccess, FlowError> + Send + Sync + 'static,
F: Fn(&T, Option<&::Object>, ::Buffer) -> Result<FlowSuccess, FlowError> + Send + Sync + 'static,
>(
pad: *mut gst_sys::GstPad,
parent: *mut gst_sys::GstObject,
@ -1206,7 +1206,7 @@ where
let res: FlowReturn = func(
&Pad::from_glib_borrow(pad).unsafe_cast(),
&from_glib_borrow(parent),
Option::<::Object>::from_glib_borrow(parent).as_ref(),
from_glib_full(buffer),
)
.into();
@ -1215,7 +1215,7 @@ where
unsafe extern "C" fn trampoline_chain_list_function<
T,
F: Fn(&T, &Option<::Object>, ::BufferList) -> Result<FlowSuccess, FlowError>
F: Fn(&T, Option<&::Object>, ::BufferList) -> Result<FlowSuccess, FlowError>
+ Send
+ Sync
+ 'static,
@ -1231,7 +1231,7 @@ where
let res: FlowReturn = func(
&Pad::from_glib_borrow(pad).unsafe_cast(),
&from_glib_borrow(parent),
Option::<::Object>::from_glib_borrow(parent).as_ref(),
from_glib_full(list),
)
.into();
@ -1240,7 +1240,7 @@ where
unsafe extern "C" fn trampoline_event_function<
T,
F: Fn(&T, &Option<::Object>, ::Event) -> bool + Send + Sync + 'static,
F: Fn(&T, Option<&::Object>, ::Event) -> bool + Send + Sync + 'static,
>(
pad: *mut gst_sys::GstPad,
parent: *mut gst_sys::GstObject,
@ -1253,7 +1253,7 @@ where
func(
&Pad::from_glib_borrow(pad).unsafe_cast(),
&from_glib_borrow(parent),
Option::<::Object>::from_glib_borrow(parent).as_ref(),
from_glib_full(event),
)
.to_glib()
@ -1261,7 +1261,7 @@ where
unsafe extern "C" fn trampoline_event_full_function<
T,
F: Fn(&T, &Option<::Object>, ::Event) -> Result<FlowSuccess, FlowError> + Send + Sync + 'static,
F: Fn(&T, Option<&::Object>, ::Event) -> Result<FlowSuccess, FlowError> + Send + Sync + 'static,
>(
pad: *mut gst_sys::GstPad,
parent: *mut gst_sys::GstObject,
@ -1274,7 +1274,7 @@ where
let res: FlowReturn = func(
&Pad::from_glib_borrow(pad).unsafe_cast(),
&from_glib_borrow(parent),
Option::<::Object>::from_glib_borrow(parent).as_ref(),
from_glib_full(event),
)
.into();
@ -1283,7 +1283,7 @@ where
unsafe extern "C" fn trampoline_getrange_function<
T,
F: Fn(&T, &Option<::Object>, u64, u32) -> Result<::Buffer, FlowError> + Send + Sync + 'static,
F: Fn(&T, Option<&::Object>, u64, u32) -> Result<::Buffer, FlowError> + Send + Sync + 'static,
>(
pad: *mut gst_sys::GstPad,
parent: *mut gst_sys::GstObject,
@ -1298,7 +1298,7 @@ where
match func(
&Pad::from_glib_borrow(pad).unsafe_cast(),
&from_glib_borrow(parent),
Option::<::Object>::from_glib_borrow(parent).as_ref(),
offset,
length,
) {
@ -1312,7 +1312,7 @@ where
unsafe extern "C" fn trampoline_iterate_internal_links_function<
T,
F: Fn(&T, &Option<::Object>) -> ::Iterator<Pad> + Send + Sync + 'static,
F: Fn(&T, Option<&::Object>) -> ::Iterator<Pad> + Send + Sync + 'static,
>(
pad: *mut gst_sys::GstPad,
parent: *mut gst_sys::GstObject,
@ -1325,7 +1325,7 @@ where
// Steal the iterator and return it
let ret = func(
&Pad::from_glib_borrow(pad).unsafe_cast(),
&from_glib_borrow(parent),
Option::<::Object>::from_glib_borrow(parent).as_ref(),
);
let ptr = ret.to_glib_none().0;
mem::forget(ret);
@ -1335,7 +1335,7 @@ where
unsafe extern "C" fn trampoline_link_function<
T,
F: Fn(&T, &Option<::Object>, &::Pad) -> Result<::PadLinkSuccess, ::PadLinkError>
F: Fn(&T, Option<&::Object>, &::Pad) -> Result<::PadLinkSuccess, ::PadLinkError>
+ Send
+ Sync
+ 'static,
@ -1351,7 +1351,7 @@ where
let res: ::PadLinkReturn = func(
&Pad::from_glib_borrow(pad).unsafe_cast(),
&from_glib_borrow(parent),
Option::<::Object>::from_glib_borrow(parent).as_ref(),
&from_glib_borrow(peer),
)
.into();
@ -1360,7 +1360,7 @@ where
unsafe extern "C" fn trampoline_query_function<
T,
F: Fn(&T, &Option<::Object>, &mut ::QueryRef) -> bool + Send + Sync + 'static,
F: Fn(&T, Option<&::Object>, &mut ::QueryRef) -> bool + Send + Sync + 'static,
>(
pad: *mut gst_sys::GstPad,
parent: *mut gst_sys::GstObject,
@ -1373,7 +1373,7 @@ where
func(
&Pad::from_glib_borrow(pad).unsafe_cast(),
&from_glib_borrow(parent),
Option::<::Object>::from_glib_borrow(parent).as_ref(),
::QueryRef::from_mut_ptr(query),
)
.to_glib()
@ -1381,7 +1381,7 @@ where
unsafe extern "C" fn trampoline_unlink_function<
T,
F: Fn(&T, &Option<::Object>) + Send + Sync + 'static,
F: Fn(&T, Option<&::Object>) + Send + Sync + 'static,
>(
pad: *mut gst_sys::GstPad,
parent: *mut gst_sys::GstObject,
@ -1392,7 +1392,7 @@ unsafe extern "C" fn trampoline_unlink_function<
func(
&Pad::from_glib_borrow(pad).unsafe_cast(),
&from_glib_borrow(parent),
Option::<::Object>::from_glib_borrow(parent).as_ref(),
)
}

View file

@ -156,7 +156,7 @@ impl SampleRef {
}
#[cfg(any(feature = "v1_16", feature = "dox"))]
pub fn set_segment(&mut self, segment: &Option<&Segment>) {
pub fn set_segment(&mut self, segment: Option<&Segment>) {
unsafe { gst_sys::gst_sample_set_segment(self.as_mut_ptr(), segment.to_glib_none().0) }
}

View file

@ -100,7 +100,7 @@ pub trait ElementImplExt {
) -> R;
fn catch_panic_pad_function<R, F: FnOnce(&Self, &::Element) -> R, G: FnOnce() -> R>(
parent: &Option<::Object>,
parent: Option<&::Object>,
fallback: G,
f: F,
) -> R;
@ -222,7 +222,7 @@ where
}
fn catch_panic_pad_function<R, F: FnOnce(&Self, &::Element) -> R, G: FnOnce() -> R>(
parent: &Option<::Object>,
parent: Option<&::Object>,
fallback: G,
f: F,
) -> R {

View file

@ -81,10 +81,10 @@ fn print_topology(info: &DiscovererStreamInfo, depth: usize) {
}
}
fn on_connect_discovered(
fn on_discovered(
_discoverer: &Discoverer,
discoverer_info: &DiscovererInfo,
error: &Option<glib::Error>,
error: Option<&glib::Error>,
) {
let uri = discoverer_info.get_uri().unwrap();
match discoverer_info.get_result() {
@ -156,7 +156,7 @@ fn run_discoverer() -> Result<(), Error> {
let loop_ = glib::MainLoop::new(None, false);
let timeout = 5 * gst::SECOND;
let discoverer = gst_pbutils::Discoverer::new(timeout)?;
discoverer.connect_discovered(on_connect_discovered);
discoverer.connect_discovered(on_discovered);
let loop_clone = loop_.clone();
discoverer.connect_finished(move |_| {
println!("\nFinished discovering");