Skip to content
This repository was archived by the owner on Jun 8, 2021. It is now read-only.

Commit 2f4e876

Browse files
committed
subclassing: move parent invocation fnct in Ext trait
This reduces the risk for the user to override them, or even worse, let the user believe that it has an actual effect to override them. See https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/merge_requests/223#note_112472
1 parent 1b9ff5a commit 2f4e876

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

src/subclass/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ pub mod prelude {
186186
//! Prelude that re-exports all important traits from this crate.
187187
pub use super::boxed::BoxedType;
188188
pub use super::interface::{ObjectInterface, ObjectInterfaceExt};
189-
pub use super::object::{ObjectClassSubclassExt, ObjectImpl};
189+
pub use super::object::{ObjectClassSubclassExt, ObjectImpl, ObjectImplExt};
190190
pub use super::types::{
191191
ClassStruct, InstanceStruct, IsImplementable, IsSubclassable, ObjectSubclass,
192192
};

src/subclass/object.rs

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ macro_rules! glib_object_impl {
3434
/// Trait for implementors of `glib::Object` subclasses.
3535
///
3636
/// This allows overriding the virtual methods of `glib::Object`.
37-
pub trait ObjectImpl: 'static {
37+
pub trait ObjectImpl: ObjectImplExt + 'static {
3838
/// Storage for the type-specific data used during registration.
3939
///
4040
/// This is usually generated by the [`glib_object_impl!`] macro.
@@ -66,20 +66,6 @@ pub trait ObjectImpl: 'static {
6666
fn constructed(&self, obj: &Object) {
6767
self.parent_constructed(obj);
6868
}
69-
70-
/// Chain up to the parent class' implementation of `glib::Object::constructed()`.
71-
///
72-
/// Do not override this, it has no effect.
73-
fn parent_constructed(&self, obj: &Object) {
74-
unsafe {
75-
let data = self.get_type_data();
76-
let parent_class = data.as_ref().get_parent_class() as *mut gobject_ffi::GObjectClass;
77-
78-
if let Some(ref func) = (*parent_class).constructed {
79-
func(obj.to_glib_none().0);
80-
}
81-
}
82-
}
8369
}
8470

8571
unsafe extern "C" fn get_property<T: ObjectSubclass>(
@@ -320,7 +306,29 @@ unsafe impl<T: ObjectSubclass> IsSubclassable<T> for ObjectClass {
320306
}
321307
}
322308

323-
pub trait ObjectImplExt: ObjectImpl + ObjectSubclass {
309+
pub trait ObjectImplExt {
310+
/// Chain up to the parent class' implementation of `glib::Object::constructed()`.
311+
fn parent_constructed(&self, obj: &Object);
312+
313+
fn signal_chain_from_overridden(
314+
&self,
315+
token: &super::SignalClassHandlerToken,
316+
values: &[Value],
317+
) -> Option<Value>;
318+
}
319+
320+
impl<T: ObjectImpl + ObjectSubclass> ObjectImplExt for T {
321+
fn parent_constructed(&self, obj: &Object) {
322+
unsafe {
323+
let data = self.get_type_data();
324+
let parent_class = data.as_ref().get_parent_class() as *mut gobject_ffi::GObjectClass;
325+
326+
if let Some(ref func) = (*parent_class).constructed {
327+
func(obj.to_glib_none().0);
328+
}
329+
}
330+
}
331+
324332
fn signal_chain_from_overridden(
325333
&self,
326334
token: &super::SignalClassHandlerToken,
@@ -336,8 +344,6 @@ pub trait ObjectImplExt: ObjectImpl + ObjectSubclass {
336344
}
337345
}
338346

339-
impl<T: ObjectImpl + ObjectSubclass> ObjectImplExt for T {}
340-
341347
#[cfg(test)]
342348
mod test {
343349
use super::super::super::object::ObjectExt;

0 commit comments

Comments
 (0)