Explicitly add dyn keyword to trait objects

Trait objects without are deprecated with the latest nightly and this
makes it more clear that we're doing dynamic dispatch anyway.
This commit is contained in:
Sebastian Dröge 2019-06-06 09:09:34 +03:00
parent 7a69a1137c
commit d1e562b9f6
15 changed files with 78 additions and 53 deletions

View file

@ -22,12 +22,16 @@ use AppSink;
#[allow(clippy::type_complexity)]
pub struct AppSinkCallbacks {
eos: Option<RefCell<Box<FnMut(&AppSink) + Send + 'static>>>,
eos: Option<RefCell<Box<dyn FnMut(&AppSink) + Send + 'static>>>,
new_preroll: Option<
RefCell<Box<FnMut(&AppSink) -> Result<gst::FlowSuccess, gst::FlowError> + Send + 'static>>,
RefCell<
Box<dyn FnMut(&AppSink) -> Result<gst::FlowSuccess, gst::FlowError> + Send + 'static>,
>,
>,
new_sample: Option<
RefCell<Box<FnMut(&AppSink) -> Result<gst::FlowSuccess, gst::FlowError> + Send + 'static>>,
RefCell<
Box<dyn FnMut(&AppSink) -> Result<gst::FlowSuccess, gst::FlowError> + Send + 'static>,
>,
>,
callbacks: gst_app_sys::GstAppSinkCallbacks,
}
@ -49,12 +53,16 @@ impl AppSinkCallbacks {
#[allow(clippy::type_complexity)]
pub struct AppSinkCallbacksBuilder {
eos: Option<RefCell<Box<FnMut(&AppSink) + Send + 'static>>>,
eos: Option<RefCell<Box<dyn FnMut(&AppSink) + Send + 'static>>>,
new_preroll: Option<
RefCell<Box<FnMut(&AppSink) -> Result<gst::FlowSuccess, gst::FlowError> + Send + 'static>>,
RefCell<
Box<dyn FnMut(&AppSink) -> Result<gst::FlowSuccess, gst::FlowError> + Send + 'static>,
>,
>,
new_sample: Option<
RefCell<Box<FnMut(&AppSink) -> Result<gst::FlowSuccess, gst::FlowError> + Send + 'static>>,
RefCell<
Box<dyn FnMut(&AppSink) -> Result<gst::FlowSuccess, gst::FlowError> + Send + 'static>,
>,
>,
}

View file

@ -17,9 +17,9 @@ use AppSrc;
#[allow(clippy::type_complexity)]
pub struct AppSrcCallbacks {
need_data: Option<RefCell<Box<FnMut(&AppSrc, u32) + Send + 'static>>>,
enough_data: Option<Box<Fn(&AppSrc) + Send + Sync + 'static>>,
seek_data: Option<Box<Fn(&AppSrc, u64) -> bool + Send + Sync + 'static>>,
need_data: Option<RefCell<Box<dyn FnMut(&AppSrc, u32) + Send + 'static>>>,
enough_data: Option<Box<dyn Fn(&AppSrc) + Send + Sync + 'static>>,
seek_data: Option<Box<dyn Fn(&AppSrc, u64) -> bool + Send + Sync + 'static>>,
callbacks: gst_app_sys::GstAppSrcCallbacks,
}
@ -41,9 +41,9 @@ impl AppSrcCallbacks {
#[allow(clippy::type_complexity)]
pub struct AppSrcCallbacksBuilder {
need_data: Option<RefCell<Box<FnMut(&AppSrc, u32) + Send + 'static>>>,
enough_data: Option<Box<Fn(&AppSrc) + Send + Sync + 'static>>,
seek_data: Option<Box<Fn(&AppSrc, u64) -> bool + Send + Sync + 'static>>,
need_data: Option<RefCell<Box<dyn FnMut(&AppSrc, u32) + Send + 'static>>>,
enough_data: Option<Box<dyn Fn(&AppSrc) + Send + Sync + 'static>>,
seek_data: Option<Box<dyn Fn(&AppSrc, u64) -> bool + Send + Sync + 'static>>,
}
impl AppSrcCallbacksBuilder {

View file

@ -15,7 +15,11 @@ use TimelineElement;
pub trait TimelineElementExtManual: 'static {
fn get_child_property(&self, name: &str) -> Option<glib::Value>;
fn set_child_property(&self, name: &str, value: &glib::ToValue) -> Result<(), glib::BoolError>;
fn set_child_property(
&self,
name: &str,
value: &dyn glib::ToValue,
) -> Result<(), glib::BoolError>;
}
impl<O: IsA<TimelineElement>> TimelineElementExtManual for O {
@ -41,7 +45,11 @@ impl<O: IsA<TimelineElement>> TimelineElementExtManual for O {
}
}
fn set_child_property(&self, name: &str, value: &glib::ToValue) -> Result<(), glib::BoolError> {
fn set_child_property(
&self,
name: &str,
value: &dyn glib::ToValue,
) -> Result<(), glib::BoolError> {
unsafe {
let found: bool = from_glib(ges_sys::ges_timeline_element_lookup_child(
self.as_ref().to_glib_none().0,

View file

@ -240,7 +240,7 @@ impl error::Error for EncodingProfileBuilderError {
"invalid parameters to build encoding profile"
}
fn cause(&self) -> Option<&error::Error> {
fn cause(&self) -> Option<&dyn error::Error> {
None
}
}

View file

@ -21,7 +21,7 @@ impl RTSPToken {
unsafe { from_glib_full(gst_rtsp_server_sys::gst_rtsp_token_new_empty()) }
}
pub fn new(values: &[(&str, &ToSendValue)]) -> Self {
pub fn new(values: &[(&str, &dyn ToSendValue)]) -> Self {
let mut token = RTSPToken::new_empty();
{

View file

@ -40,7 +40,7 @@ macro_rules! event_builder_generic_impl {
}
}
pub fn other_fields(self, other_fields: &[(&'a str, &'a ToSendValue)]) -> Self {
pub fn other_fields(self, other_fields: &[(&'a str, &'a dyn ToSendValue)]) -> Self {
Self {
other_fields: self.other_fields.iter().cloned()
.chain(other_fields.iter().cloned())
@ -84,7 +84,7 @@ pub fn new_downstream_force_key_unit_event<'a>() -> DownstreamForceKeyUnitEventB
pub struct DownstreamForceKeyUnitEventBuilder<'a> {
seqnum: Option<gst::Seqnum>,
running_time_offset: Option<i64>,
other_fields: Vec<(&'a str, &'a ToSendValue)>,
other_fields: Vec<(&'a str, &'a dyn ToSendValue)>,
timestamp: gst::ClockTime,
stream_time: gst::ClockTime,
running_time: gst::ClockTime,
@ -197,7 +197,7 @@ pub fn new_upstream_force_key_unit_event<'a>() -> UpstreamForceKeyUnitEventBuild
pub struct UpstreamForceKeyUnitEventBuilder<'a> {
seqnum: Option<gst::Seqnum>,
running_time_offset: Option<i64>,
other_fields: Vec<(&'a str, &'a ToSendValue)>,
other_fields: Vec<(&'a str, &'a dyn ToSendValue)>,
running_time: gst::ClockTime,
all_headers: bool,
count: u32,
@ -299,7 +299,7 @@ pub fn new_still_frame_event<'a>(in_still: bool) -> StillFrameEventBuilder<'a> {
pub struct StillFrameEventBuilder<'a> {
seqnum: Option<gst::Seqnum>,
running_time_offset: Option<i64>,
other_fields: Vec<(&'a str, &'a ToSendValue)>,
other_fields: Vec<(&'a str, &'a dyn ToSendValue)>,
in_still: bool,
}

View file

@ -44,7 +44,7 @@ impl Caps {
unsafe { from_glib_full(gst_sys::gst_caps_new_any()) }
}
pub fn new_simple(name: &str, values: &[(&str, &ToSendValue)]) -> Self {
pub fn new_simple(name: &str, values: &[(&str, &dyn ToSendValue)]) -> Self {
assert_initialized_main_thread!();
let mut caps = Caps::new_empty();
@ -126,7 +126,7 @@ impl fmt::Display for Caps {
}
impl CapsRef {
pub fn set_simple(&mut self, values: &[(&str, &ToSendValue)]) {
pub fn set_simple(&mut self, values: &[(&str, &dyn ToSendValue)]) {
for &(name, value) in values {
let value = value.to_value();

View file

@ -15,7 +15,11 @@ use ChildProxy;
pub trait ChildProxyExtManual: 'static {
fn get_child_property(&self, name: &str) -> Option<glib::Value>;
fn set_child_property(&self, name: &str, value: &glib::ToValue) -> Result<(), glib::BoolError>;
fn set_child_property(
&self,
name: &str,
value: &dyn glib::ToValue,
) -> Result<(), glib::BoolError>;
}
impl<O: IsA<ChildProxy>> ChildProxyExtManual for O {
@ -41,7 +45,11 @@ impl<O: IsA<ChildProxy>> ChildProxyExtManual for O {
}
}
fn set_child_property(&self, name: &str, value: &glib::ToValue) -> Result<(), glib::BoolError> {
fn set_child_property(
&self,
name: &str,
value: &dyn glib::ToValue,
) -> Result<(), glib::BoolError> {
unsafe {
let found: bool = from_glib(gst_sys::gst_child_proxy_lookup(
self.as_ref().to_glib_none().0,

View file

@ -917,7 +917,7 @@ declare_concrete_event!(CustomBothOob);
struct EventBuilder<'a> {
seqnum: Option<Seqnum>,
running_time_offset: Option<i64>,
other_fields: Vec<(&'a str, &'a ToSendValue)>,
other_fields: Vec<(&'a str, &'a dyn ToSendValue)>,
}
impl<'a> EventBuilder<'a> {
@ -943,7 +943,7 @@ impl<'a> EventBuilder<'a> {
}
}
fn other_fields(self, other_fields: &[(&'a str, &'a ToSendValue)]) -> Self {
fn other_fields(self, other_fields: &[(&'a str, &'a dyn ToSendValue)]) -> Self {
Self {
other_fields: self
.other_fields
@ -975,7 +975,7 @@ macro_rules! event_builder_generic_impl {
}
#[allow(clippy::needless_update)]
pub fn other_fields(self, other_fields: &[(&'a str, &'a ToSendValue)]) -> Self {
pub fn other_fields(self, other_fields: &[(&'a str, &'a dyn ToSendValue)]) -> Self {
Self {
builder: self.builder.other_fields(other_fields),
.. self

View file

@ -91,7 +91,7 @@ where
let it = self.to_glib_none().0;
mem::forget(self);
let func_box: Box<Fn(T) -> bool + Send + Sync + 'static> = Box::new(func);
let func_box: Box<dyn Fn(T) -> bool + Send + Sync + 'static> = Box::new(func);
let mut closure_value = glib::Value::from_type(from_glib(filter_boxed_get_type::<T>()));
gobject_sys::g_value_set_boxed(
closure_value.to_glib_none_mut().0,
@ -336,7 +336,7 @@ where
let func = func as *const gobject_sys::GValue;
let func = gobject_sys::g_value_get_boxed(func);
#[allow(clippy::transmute_ptr_to_ref)]
let func: &&(Fn(T) -> bool + Send + Sync + 'static) = mem::transmute(func);
let func: &&(dyn Fn(T) -> bool + Send + Sync + 'static) = mem::transmute(func);
let value = &*(value as *const glib::Value);
let value = value.get::<T>().unwrap();
@ -349,7 +349,7 @@ where
}
unsafe extern "C" fn filter_boxed_ref<T: 'static>(boxed: gpointer) -> gpointer {
let boxed = Arc::from_raw(boxed as *const (Box<Fn(T) -> bool + Send + Sync + 'static>));
let boxed = Arc::from_raw(boxed as *const (Box<dyn Fn(T) -> bool + Send + Sync + 'static>));
let copy = Arc::clone(&boxed);
// Forget it and keep it alive, we will still need it later
@ -359,7 +359,7 @@ unsafe extern "C" fn filter_boxed_ref<T: 'static>(boxed: gpointer) -> gpointer {
}
unsafe extern "C" fn filter_boxed_unref<T: 'static>(boxed: gpointer) {
let _ = Arc::from_raw(boxed as *const (Box<Fn(T) -> bool + Send + Sync + 'static>));
let _ = Arc::from_raw(boxed as *const (Box<dyn Fn(T) -> bool + Send + Sync + 'static>));
}
unsafe extern "C" fn filter_boxed_get_type<T: StaticType + 'static>() -> glib_sys::GType {

View file

@ -1192,7 +1192,7 @@ struct MessageBuilder<'a> {
src: Option<Object>,
seqnum: Option<Seqnum>,
#[allow(unused)]
other_fields: Vec<(&'a str, &'a ToSendValue)>,
other_fields: Vec<(&'a str, &'a dyn ToSendValue)>,
}
impl<'a> MessageBuilder<'a> {
@ -1222,7 +1222,7 @@ impl<'a> MessageBuilder<'a> {
}
#[cfg(any(feature = "v1_14", feature = "dox"))]
fn other_fields(self, other_fields: &[(&'a str, &'a ToSendValue)]) -> Self {
fn other_fields(self, other_fields: &[(&'a str, &'a dyn ToSendValue)]) -> Self {
Self {
other_fields: self
.other_fields
@ -1255,7 +1255,7 @@ macro_rules! message_builder_generic_impl {
#[cfg(any(feature = "v1_14", feature = "dox"))]
#[allow(clippy::needless_update)]
pub fn other_fields(self, other_fields: &[(&'a str, &'a ToSendValue)]) -> Self {
pub fn other_fields(self, other_fields: &[(&'a str, &'a dyn ToSendValue)]) -> Self {
Self {
builder: self.builder.other_fields(other_fields),
.. self
@ -1746,7 +1746,7 @@ pub struct StreamStatusBuilder<'a> {
builder: MessageBuilder<'a>,
type_: ::StreamStatusType,
owner: &'a ::Element,
status_object: Option<&'a glib::ToSendValue>,
status_object: Option<&'a dyn glib::ToSendValue>,
}
impl<'a> StreamStatusBuilder<'a> {
fn new(type_: ::StreamStatusType, owner: &'a ::Element) -> Self {
@ -1759,7 +1759,7 @@ impl<'a> StreamStatusBuilder<'a> {
}
}
pub fn status_object(self, status_object: &'a glib::ToSendValue) -> Self {
pub fn status_object(self, status_object: &'a dyn glib::ToSendValue) -> Self {
Self {
status_object: Some(status_object),
..self
@ -2225,7 +2225,7 @@ impl<'a> DeviceRemovedBuilder<'a> {
pub struct PropertyNotifyBuilder<'a> {
builder: MessageBuilder<'a>,
property_name: &'a str,
value: Option<&'a glib::ToSendValue>,
value: Option<&'a dyn glib::ToSendValue>,
}
#[cfg(any(feature = "v1_10", feature = "dox"))]
impl<'a> PropertyNotifyBuilder<'a> {
@ -2238,7 +2238,7 @@ impl<'a> PropertyNotifyBuilder<'a> {
}
}
pub fn value(self, value: &'a glib::ToSendValue) -> Self {
pub fn value(self, value: &'a dyn glib::ToSendValue) -> Self {
Self {
value: Some(value),
..self

View file

@ -933,7 +933,7 @@ impl<O: IsA<Pad>> PadExtManual for O {
user_data: glib_sys::gpointer,
) -> glib_sys::gboolean {
let func =
user_data as *mut &mut (FnMut(Event) -> Result<Option<Event>, Option<Event>>);
user_data as *mut &mut (dyn FnMut(Event) -> Result<Option<Event>, Option<Event>>);
let res = (*func)(from_glib_full(*event));
match res {
@ -958,9 +958,10 @@ impl<O: IsA<Pad>> PadExtManual for O {
unsafe {
let mut func = func;
let func_obj: &mut (FnMut(Event) -> Result<Option<Event>, Option<Event>>) = &mut func;
let func_obj: &mut (dyn FnMut(Event) -> Result<Option<Event>, Option<Event>>) =
&mut func;
let func_ptr = &func_obj
as *const &mut (FnMut(Event) -> Result<Option<Event>, Option<Event>>)
as *const &mut (dyn FnMut(Event) -> Result<Option<Event>, Option<Event>>)
as glib_sys::gpointer;
gst_sys::gst_pad_sticky_events_foreach(

View file

@ -46,7 +46,7 @@ impl Structure {
}
}
pub fn new(name: &str, values: &[(&str, &ToSendValue)]) -> Structure {
pub fn new(name: &str, values: &[(&str, &dyn ToSendValue)]) -> Structure {
assert_initialized_main_thread!();
let mut structure = Structure::new_empty(name);

View file

@ -88,9 +88,9 @@ impl<'a> TypeFind<'a> {
unsafe impl<'a> Send for TypeFind<'a> {}
impl TypeFindFactory {
pub fn call_function(&self, find: &mut TypeFindImpl) {
pub fn call_function(&self, find: &mut dyn TypeFindImpl) {
unsafe {
let find_ptr = &find as *const &mut TypeFindImpl as glib_sys::gpointer;
let find_ptr = &find as *const &mut dyn TypeFindImpl as glib_sys::gpointer;
let mut find = gst_sys::GstTypeFind {
peek: Some(type_find_peek),
suggest: Some(type_find_suggest),
@ -119,7 +119,7 @@ unsafe extern "C" fn type_find_closure_drop<F: Fn(&mut TypeFind) + Send + Sync +
}
unsafe extern "C" fn type_find_peek(data: glib_sys::gpointer, offset: i64, size: u32) -> *const u8 {
let find: &mut &mut TypeFindImpl = &mut *(data as *mut &mut TypeFindImpl);
let find: &mut &mut dyn TypeFindImpl = &mut *(data as *mut &mut dyn TypeFindImpl);
match find.peek(offset, size) {
None => ptr::null(),
Some(data) => data.as_ptr(),
@ -131,14 +131,14 @@ unsafe extern "C" fn type_find_suggest(
probability: u32,
caps: *mut gst_sys::GstCaps,
) {
let find: &mut &mut TypeFindImpl = &mut *(data as *mut &mut TypeFindImpl);
let find: &mut &mut dyn TypeFindImpl = &mut *(data as *mut &mut dyn TypeFindImpl);
find.suggest(from_glib(probability as i32), &from_glib_borrow(caps));
}
unsafe extern "C" fn type_find_get_length(data: glib_sys::gpointer) -> u64 {
use std::u64;
let find: &mut &mut TypeFindImpl = &mut *(data as *mut &mut TypeFindImpl);
let find: &mut &mut dyn TypeFindImpl = &mut *(data as *mut &mut dyn TypeFindImpl);
find.get_length().unwrap_or(u64::MAX)
}

View file

@ -580,7 +580,7 @@ pub struct Array<'a>(Cow<'a, [glib::SendValue]>);
unsafe impl<'a> Send for Array<'a> {}
impl<'a> Array<'a> {
pub fn new(values: &[&ToSendValue]) -> Self {
pub fn new(values: &[&dyn ToSendValue]) -> Self {
assert_initialized_main_thread!();
Array(values.iter().map(|v| v.to_send_value()).collect())
@ -601,8 +601,8 @@ impl<'a> Array<'a> {
}
}
impl<'a> From<&'a [&'a ToSendValue]> for Array<'a> {
fn from(values: &'a [&'a ToSendValue]) -> Self {
impl<'a> From<&'a [&'a dyn ToSendValue]> for Array<'a> {
fn from(values: &'a [&'a dyn ToSendValue]) -> Self {
skip_assert_initialized!();
Self::new(values)
@ -658,7 +658,7 @@ pub struct List<'a>(Cow<'a, [glib::SendValue]>);
unsafe impl<'a> Send for List<'a> {}
impl<'a> List<'a> {
pub fn new(values: &[&ToSendValue]) -> Self {
pub fn new(values: &[&dyn ToSendValue]) -> Self {
assert_initialized_main_thread!();
List(values.iter().map(|v| v.to_send_value()).collect())
@ -679,8 +679,8 @@ impl<'a> List<'a> {
}
}
impl<'a> From<&'a [&'a ToSendValue]> for List<'a> {
fn from(values: &'a [&'a ToSendValue]) -> Self {
impl<'a> From<&'a [&'a dyn ToSendValue]> for List<'a> {
fn from(values: &'a [&'a dyn ToSendValue]) -> Self {
skip_assert_initialized!();
Self::new(values)