From 3c8aacc56d61292f86c209ffa27f063373d399d8 Mon Sep 17 00:00:00 2001 From: Fina Wilke Date: Tue, 24 Sep 2024 21:19:26 +0200 Subject: [PATCH 1/3] Add additional type bounds to Impl traits Remove the Sealed traits, as they are now unnecessary. --- gdk-pixbuf/src/subclass/pixbuf_animation.rs | 44 +++++++--- .../src/subclass/pixbuf_animation_iter.rs | 45 +++++++--- gdk-pixbuf/src/subclass/pixbuf_loader.rs | 43 ++++++--- gio/src/subclass/action_group.rs | 87 ++++++++++++++----- gio/src/subclass/action_map.rs | 32 ++++--- gio/src/subclass/application.rs | 75 +++++++++++----- gio/src/subclass/async_initable.rs | 30 ++++--- gio/src/subclass/initable.rs | 27 +++--- gio/src/subclass/input_stream.rs | 41 ++++++--- gio/src/subclass/io_stream.rs | 37 +++++--- gio/src/subclass/list_model.rs | 25 +++--- gio/src/subclass/output_stream.rs | 45 +++++++--- gio/src/subclass/seekable.rs | 47 +++++++--- gio/src/subclass/socket_control_message.rs | 49 ++++++++--- glib/src/gobject/dynamic_object.rs | 1 + glib/src/subclass/object.rs | 9 +- glib/src/subclass/type_module.rs | 30 +++++-- glib/src/subclass/type_plugin.rs | 43 +++++++-- 18 files changed, 496 insertions(+), 214 deletions(-) diff --git a/gdk-pixbuf/src/subclass/pixbuf_animation.rs b/gdk-pixbuf/src/subclass/pixbuf_animation.rs index 4a014d8be908..ee5ff297496d 100644 --- a/gdk-pixbuf/src/subclass/pixbuf_animation.rs +++ b/gdk-pixbuf/src/subclass/pixbuf_animation.rs @@ -13,7 +13,10 @@ use glib::{prelude::*, subclass::prelude::*, translate::*}; use crate::{ffi, Pixbuf, PixbufAnimation, PixbufAnimationIter}; -pub trait PixbufAnimationImpl: ObjectImpl { +pub trait PixbufAnimationImpl: ObjectImpl +where + ::Type: IsA, +{ fn is_static_image(&self) -> bool { self.parent_is_static_image() } @@ -31,12 +34,10 @@ pub trait PixbufAnimationImpl: ObjectImpl { } } -mod sealed { - pub trait Sealed {} - impl Sealed for T {} -} - -pub trait PixbufAnimationImplExt: sealed::Sealed + ObjectSubclass { +pub trait PixbufAnimationImplExt: ObjectSubclass + PixbufAnimationImpl +where + ::Type: IsA, +{ fn parent_is_static_image(&self) -> bool { unsafe { let data = Self::type_data(); @@ -116,9 +117,15 @@ pub trait PixbufAnimationImplExt: sealed::Sealed + ObjectSubclass { } } -impl PixbufAnimationImplExt for T {} +impl PixbufAnimationImplExt for T where + ::Type: IsA +{ +} -unsafe impl IsSubclassable for PixbufAnimation { +unsafe impl IsSubclassable for PixbufAnimation +where + ::Type: IsA, +{ fn class_init(class: &mut ::glib::Class) { Self::parent_class_init::(class); @@ -132,7 +139,10 @@ unsafe impl IsSubclassable for PixbufAnimation { unsafe extern "C" fn animation_is_static_image( ptr: *mut ffi::GdkPixbufAnimation, -) -> glib::ffi::gboolean { +) -> glib::ffi::gboolean +where + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); @@ -143,7 +153,9 @@ unsafe extern "C" fn animation_get_size( ptr: *mut ffi::GdkPixbufAnimation, width_ptr: *mut libc::c_int, height_ptr: *mut libc::c_int, -) { +) where + ::Type: IsA, +{ if width_ptr.is_null() && height_ptr.is_null() { return; } @@ -162,7 +174,10 @@ unsafe extern "C" fn animation_get_size( unsafe extern "C" fn animation_get_static_image( ptr: *mut ffi::GdkPixbufAnimation, -) -> *mut ffi::GdkPixbuf { +) -> *mut ffi::GdkPixbuf +where + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); @@ -192,7 +207,10 @@ unsafe extern "C" fn animation_get_static_image( unsafe extern "C" fn animation_get_iter( ptr: *mut ffi::GdkPixbufAnimation, start_time_ptr: *const glib::ffi::GTimeVal, -) -> *mut ffi::GdkPixbufAnimationIter { +) -> *mut ffi::GdkPixbufAnimationIter +where + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); diff --git a/gdk-pixbuf/src/subclass/pixbuf_animation_iter.rs b/gdk-pixbuf/src/subclass/pixbuf_animation_iter.rs index 99d05ccae3ae..03e16a1db22c 100644 --- a/gdk-pixbuf/src/subclass/pixbuf_animation_iter.rs +++ b/gdk-pixbuf/src/subclass/pixbuf_animation_iter.rs @@ -12,7 +12,10 @@ use glib::{prelude::*, subclass::prelude::*, translate::*}; use crate::{ffi, Pixbuf, PixbufAnimationIter}; -pub trait PixbufAnimationIterImpl: ObjectImpl { +pub trait PixbufAnimationIterImpl: ObjectImpl +where + ::Type: IsA, +{ // rustdoc-stripper-ignore-next /// Time in milliseconds, returning `None` implies showing the same pixbuf forever. fn delay_time(&self) -> Option { @@ -32,12 +35,10 @@ pub trait PixbufAnimationIterImpl: ObjectImpl { } } -mod sealed { - pub trait Sealed {} - impl Sealed for T {} -} - -pub trait PixbufAnimationIterImplExt: sealed::Sealed + ObjectSubclass { +pub trait PixbufAnimationIterImplExt: ObjectSubclass + PixbufAnimationIterImpl +where + ::Type: IsA, +{ fn parent_delay_time(&self) -> Option { unsafe { let data = Self::type_data(); @@ -121,9 +122,15 @@ pub trait PixbufAnimationIterImplExt: sealed::Sealed + ObjectSubclass { } } -impl PixbufAnimationIterImplExt for T {} +impl PixbufAnimationIterImplExt for T where + ::Type: IsA +{ +} -unsafe impl IsSubclassable for PixbufAnimationIter { +unsafe impl IsSubclassable for PixbufAnimationIter +where + ::Type: IsA, +{ fn class_init(class: &mut ::glib::Class) { Self::parent_class_init::(class); @@ -137,7 +144,10 @@ unsafe impl IsSubclassable for PixbufAnimationIte unsafe extern "C" fn animation_iter_get_delay_time( ptr: *mut ffi::GdkPixbufAnimationIter, -) -> i32 { +) -> i32 +where + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); @@ -146,7 +156,10 @@ unsafe extern "C" fn animation_iter_get_delay_time( unsafe extern "C" fn animation_iter_get_pixbuf( ptr: *mut ffi::GdkPixbufAnimationIter, -) -> *mut ffi::GdkPixbuf { +) -> *mut ffi::GdkPixbuf +where + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); @@ -162,7 +175,10 @@ unsafe extern "C" fn animation_iter_get_pixbuf( unsafe extern "C" fn animation_iter_on_currently_loading_frame( ptr: *mut ffi::GdkPixbufAnimationIter, -) -> glib::ffi::gboolean { +) -> glib::ffi::gboolean +where + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); @@ -172,7 +188,10 @@ unsafe extern "C" fn animation_iter_on_currently_loading_frame( ptr: *mut ffi::GdkPixbufAnimationIter, current_time_ptr: *const glib::ffi::GTimeVal, -) -> glib::ffi::gboolean { +) -> glib::ffi::gboolean +where + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); diff --git a/gdk-pixbuf/src/subclass/pixbuf_loader.rs b/gdk-pixbuf/src/subclass/pixbuf_loader.rs index c2d53a7132f5..e99388644043 100644 --- a/gdk-pixbuf/src/subclass/pixbuf_loader.rs +++ b/gdk-pixbuf/src/subclass/pixbuf_loader.rs @@ -7,7 +7,10 @@ use glib::{prelude::*, subclass::prelude::*, translate::*}; use crate::{ffi, PixbufLoader}; -pub trait PixbufLoaderImpl: ObjectImpl { +pub trait PixbufLoaderImpl: ObjectImpl +where + ::Type: IsA, +{ fn size_prepared(&self, width: i32, height: i32) { self.parent_size_prepared(width, height) } @@ -25,12 +28,10 @@ pub trait PixbufLoaderImpl: ObjectImpl { } } -mod sealed { - pub trait Sealed {} - impl Sealed for T {} -} - -pub trait PixbufLoaderImplExt: sealed::Sealed + ObjectSubclass { +pub trait PixbufLoaderImplExt: ObjectSubclass + PixbufLoaderImpl +where + ::Type: IsA, +{ fn parent_size_prepared(&self, width: i32, height: i32) { unsafe { let data = Self::type_data(); @@ -96,9 +97,15 @@ pub trait PixbufLoaderImplExt: sealed::Sealed + ObjectSubclass { } } -impl PixbufLoaderImplExt for T {} +impl PixbufLoaderImplExt for T where + ::Type: IsA +{ +} -unsafe impl IsSubclassable for PixbufLoader { +unsafe impl IsSubclassable for PixbufLoader +where + ::Type: IsA, +{ fn class_init(class: &mut ::glib::Class) { Self::parent_class_init::(class); @@ -114,14 +121,19 @@ unsafe extern "C" fn loader_size_prepared( ptr: *mut ffi::GdkPixbufLoader, width: i32, height: i32, -) { +) where + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); imp.size_prepared(width, height) } -unsafe extern "C" fn loader_area_prepared(ptr: *mut ffi::GdkPixbufLoader) { +unsafe extern "C" fn loader_area_prepared(ptr: *mut ffi::GdkPixbufLoader) +where + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); @@ -134,14 +146,19 @@ unsafe extern "C" fn loader_area_updated( y: i32, width: i32, height: i32, -) { +) where + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); imp.area_updated(x, y, width, height) } -unsafe extern "C" fn loader_closed(ptr: *mut ffi::GdkPixbufLoader) { +unsafe extern "C" fn loader_closed(ptr: *mut ffi::GdkPixbufLoader) +where + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); diff --git a/gio/src/subclass/action_group.rs b/gio/src/subclass/action_group.rs index 948fb2d318c8..ca895077889a 100644 --- a/gio/src/subclass/action_group.rs +++ b/gio/src/subclass/action_group.rs @@ -6,7 +6,10 @@ use glib::{prelude::*, subclass::prelude::*, translate::*, GString, Quark, Varia use crate::{ffi, ActionGroup}; -pub trait ActionGroupImpl: ObjectImpl { +pub trait ActionGroupImpl: ObjectImpl +where + ::Type: IsA, +{ fn action_added(&self, action_name: &str) { self.parent_action_added(action_name); } @@ -73,12 +76,10 @@ pub trait ActionGroupImpl: ObjectImpl { )>; } -mod sealed { - pub trait Sealed {} - impl Sealed for T {} -} - -pub trait ActionGroupImplExt: sealed::Sealed + ObjectSubclass { +pub trait ActionGroupImplExt: ObjectSubclass + ActionGroupImpl +where + ::Type: IsA, +{ fn parent_action_added(&self, action_name: &str) { unsafe { let type_data = Self::type_data(); @@ -341,9 +342,13 @@ pub trait ActionGroupImplExt: sealed::Sealed + ObjectSubclass { } } -impl ActionGroupImplExt for T {} +impl ActionGroupImplExt for T where ::Type: IsA +{} -unsafe impl IsImplementable for ActionGroup { +unsafe impl IsImplementable for ActionGroup +where + ::Type: IsA, +{ fn interface_init(iface: &mut glib::Interface) { let iface = iface.as_mut(); @@ -367,7 +372,10 @@ unsafe impl IsImplementable for ActionGroup { unsafe extern "C" fn action_group_has_action( action_group: *mut ffi::GActionGroup, action_nameptr: *const libc::c_char, -) -> glib::ffi::gboolean { +) -> glib::ffi::gboolean +where + ::Type: IsA, +{ let instance = &*(action_group as *mut T::Instance); let action_name = GString::from_glib_borrow(action_nameptr); let imp = instance.imp(); @@ -378,7 +386,10 @@ unsafe extern "C" fn action_group_has_action( unsafe extern "C" fn action_group_get_action_enabled( action_group: *mut ffi::GActionGroup, action_nameptr: *const libc::c_char, -) -> glib::ffi::gboolean { +) -> glib::ffi::gboolean +where + ::Type: IsA, +{ let instance = &*(action_group as *mut T::Instance); let imp = instance.imp(); let action_name = GString::from_glib_borrow(action_nameptr); @@ -399,7 +410,10 @@ impl Drop for PtrHolder { unsafe extern "C" fn action_group_get_action_parameter_type( action_group: *mut ffi::GActionGroup, action_nameptr: *const libc::c_char, -) -> *const glib::ffi::GVariantType { +) -> *const glib::ffi::GVariantType +where + ::Type: IsA, +{ let instance = &*(action_group as *mut T::Instance); let imp = instance.imp(); let action_name = GString::from_glib_borrow(action_nameptr); @@ -428,7 +442,10 @@ unsafe extern "C" fn action_group_get_action_parameter_type( unsafe extern "C" fn action_group_get_action_state_type( action_group: *mut ffi::GActionGroup, action_nameptr: *const libc::c_char, -) -> *const glib::ffi::GVariantType { +) -> *const glib::ffi::GVariantType +where + ::Type: IsA, +{ let instance = &*(action_group as *mut T::Instance); let imp = instance.imp(); let action_name = GString::from_glib_borrow(action_nameptr); @@ -457,7 +474,10 @@ unsafe extern "C" fn action_group_get_action_state_type( unsafe extern "C" fn action_group_get_action_state_hint( action_group: *mut ffi::GActionGroup, action_nameptr: *const libc::c_char, -) -> *mut glib::ffi::GVariant { +) -> *mut glib::ffi::GVariant +where + ::Type: IsA, +{ let instance = &*(action_group as *mut T::Instance); let imp = instance.imp(); let action_name = GString::from_glib_borrow(action_nameptr); @@ -485,7 +505,10 @@ unsafe extern "C" fn action_group_get_action_state_hint( unsafe extern "C" fn action_group_get_action_state( action_group: *mut ffi::GActionGroup, action_nameptr: *const libc::c_char, -) -> *mut glib::ffi::GVariant { +) -> *mut glib::ffi::GVariant +where + ::Type: IsA, +{ let instance = &*(action_group as *mut T::Instance); let imp = instance.imp(); let action_name = GString::from_glib_borrow(action_nameptr); @@ -512,7 +535,9 @@ unsafe extern "C" fn action_group_change_action_state( action_group: *mut ffi::GActionGroup, action_nameptr: *const libc::c_char, stateptr: *mut glib::ffi::GVariant, -) { +) where + ::Type: IsA, +{ let instance = &*(action_group as *mut T::Instance); let imp = instance.imp(); let action_name = GString::from_glib_borrow(action_nameptr); @@ -525,7 +550,9 @@ unsafe extern "C" fn action_group_activate_action( action_group: *mut ffi::GActionGroup, action_nameptr: *const libc::c_char, parameterptr: *mut glib::ffi::GVariant, -) { +) where + ::Type: IsA, +{ let instance = &*(action_group as *mut T::Instance); let imp = instance.imp(); let action_name = GString::from_glib_borrow(action_nameptr); @@ -537,7 +564,9 @@ unsafe extern "C" fn action_group_activate_action( unsafe extern "C" fn action_group_action_added( action_group: *mut ffi::GActionGroup, action_nameptr: *const libc::c_char, -) { +) where + ::Type: IsA, +{ let instance = &*(action_group as *mut T::Instance); let imp = instance.imp(); let action_name = GString::from_glib_borrow(action_nameptr); @@ -548,7 +577,9 @@ unsafe extern "C" fn action_group_action_added( unsafe extern "C" fn action_group_action_removed( action_group: *mut ffi::GActionGroup, action_nameptr: *const libc::c_char, -) { +) where + ::Type: IsA, +{ let instance = &*(action_group as *mut T::Instance); let imp = instance.imp(); let action_name = GString::from_glib_borrow(action_nameptr); @@ -560,7 +591,9 @@ unsafe extern "C" fn action_group_action_enabled_changed( action_group: *mut ffi::GActionGroup, action_nameptr: *const libc::c_char, enabled: glib::ffi::gboolean, -) { +) where + ::Type: IsA, +{ let instance = &*(action_group as *mut T::Instance); let imp = instance.imp(); let action_name = GString::from_glib_borrow(action_nameptr); @@ -572,7 +605,9 @@ unsafe extern "C" fn action_group_action_state_changed( action_group: *mut ffi::GActionGroup, action_nameptr: *const libc::c_char, stateptr: *mut glib::ffi::GVariant, -) { +) where + ::Type: IsA, +{ let instance = &*(action_group as *mut T::Instance); let imp = instance.imp(); let action_name = GString::from_glib_borrow(action_nameptr); @@ -583,7 +618,10 @@ unsafe extern "C" fn action_group_action_state_changed( unsafe extern "C" fn action_group_list_actions( action_group: *mut ffi::GActionGroup, -) -> *mut *mut libc::c_char { +) -> *mut *mut libc::c_char +where + ::Type: IsA, +{ let instance = &*(action_group as *mut T::Instance); let imp = instance.imp(); @@ -609,7 +647,10 @@ unsafe extern "C" fn action_group_query_action( state_type: *mut *const glib::ffi::GVariantType, state_hint: *mut *mut glib::ffi::GVariant, state: *mut *mut glib::ffi::GVariant, -) -> glib::ffi::gboolean { +) -> glib::ffi::gboolean +where + ::Type: IsA, +{ let instance = &*(action_group as *mut T::Instance); let imp = instance.imp(); let action_name = GString::from_glib_borrow(action_nameptr); diff --git a/gio/src/subclass/action_map.rs b/gio/src/subclass/action_map.rs index d7a668ee33e7..13b21ca01afc 100644 --- a/gio/src/subclass/action_map.rs +++ b/gio/src/subclass/action_map.rs @@ -6,18 +6,19 @@ use glib::{prelude::*, subclass::prelude::*, translate::*, GString, Quark}; use crate::{ffi, Action, ActionMap}; -pub trait ActionMapImpl: ObjectImpl { +pub trait ActionMapImpl: ObjectImpl +where + ::Type: IsA, +{ fn lookup_action(&self, action_name: &str) -> Option; fn add_action(&self, action: &Action); fn remove_action(&self, action_name: &str); } -mod sealed { - pub trait Sealed {} - impl Sealed for T {} -} - -pub trait ActionMapImplExt: sealed::Sealed + ObjectSubclass { +pub trait ActionMapImplExt: ObjectSubclass + ActionMapImpl +where + ::Type: IsA, +{ fn parent_lookup_action(&self, name: &str) -> Option { unsafe { let type_data = Self::type_data(); @@ -68,11 +69,11 @@ pub trait ActionMapImplExt: sealed::Sealed + ObjectSubclass { } } -impl ActionMapImplExt for T {} +impl ActionMapImplExt for T where ::Type: IsA {} unsafe impl IsImplementable for ActionMap where - ::Type: IsA, + ::Type: IsA, { fn interface_init(iface: &mut glib::Interface) { let iface = iface.as_mut(); @@ -86,7 +87,10 @@ where unsafe extern "C" fn action_map_lookup_action( action_map: *mut ffi::GActionMap, action_nameptr: *const libc::c_char, -) -> *mut ffi::GAction { +) -> *mut ffi::GAction +where + ::Type: IsA, +{ let instance = &*(action_map as *mut T::Instance); let action_name = GString::from_glib_borrow(action_nameptr); let imp = instance.imp(); @@ -116,7 +120,9 @@ unsafe extern "C" fn action_map_lookup_action( unsafe extern "C" fn action_map_add_action( action_map: *mut ffi::GActionMap, actionptr: *mut ffi::GAction, -) { +) where + ::Type: IsA, +{ let instance = &*(action_map as *mut T::Instance); let imp = instance.imp(); let action: Borrowed = from_glib_borrow(actionptr); @@ -127,7 +133,9 @@ unsafe extern "C" fn action_map_add_action( unsafe extern "C" fn action_map_remove_action( action_map: *mut ffi::GActionMap, action_nameptr: *const libc::c_char, -) { +) where + ::Type: IsA, +{ let instance = &*(action_map as *mut T::Instance); let imp = instance.imp(); let action_name = GString::from_glib_borrow(action_nameptr); diff --git a/gio/src/subclass/application.rs b/gio/src/subclass/application.rs index 5a863c388d17..b9962f15078d 100644 --- a/gio/src/subclass/application.rs +++ b/gio/src/subclass/application.rs @@ -64,7 +64,10 @@ impl From for Vec { } } -pub trait ApplicationImpl: ObjectImpl + ApplicationImplExt { +pub trait ApplicationImpl: ObjectImpl +where + ::Type: IsA, +{ fn activate(&self) { self.parent_activate() } @@ -110,12 +113,10 @@ pub trait ApplicationImpl: ObjectImpl + ApplicationImplExt { } } -mod sealed { - pub trait Sealed {} - impl Sealed for T {} -} - -pub trait ApplicationImplExt: sealed::Sealed + ObjectSubclass { +pub trait ApplicationImplExt: ObjectSubclass + ApplicationImpl +where + ::Type: IsA, +{ fn parent_activate(&self) { unsafe { let data = Self::type_data(); @@ -271,9 +272,13 @@ pub trait ApplicationImplExt: sealed::Sealed + ObjectSubclass { } } -impl ApplicationImplExt for T {} +impl ApplicationImplExt for T where ::Type: IsA +{} -unsafe impl IsSubclassable for Application { +unsafe impl IsSubclassable for Application +where + ::Type: IsA, +{ fn class_init(class: &mut ::glib::Class) { Self::parent_class_init::(class); @@ -292,7 +297,10 @@ unsafe impl IsSubclassable for Application { } } -unsafe extern "C" fn application_activate(ptr: *mut ffi::GApplication) { +unsafe extern "C" fn application_activate(ptr: *mut ffi::GApplication) +where + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); @@ -302,7 +310,9 @@ unsafe extern "C" fn application_activate(ptr: *mut ffi::GAp unsafe extern "C" fn application_after_emit( ptr: *mut ffi::GApplication, platform_data: *mut glib::ffi::GVariant, -) { +) where + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); @@ -311,7 +321,9 @@ unsafe extern "C" fn application_after_emit( unsafe extern "C" fn application_before_emit( ptr: *mut ffi::GApplication, platform_data: *mut glib::ffi::GVariant, -) { +) where + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); @@ -320,7 +332,10 @@ unsafe extern "C" fn application_before_emit( unsafe extern "C" fn application_command_line( ptr: *mut ffi::GApplication, command_line: *mut ffi::GApplicationCommandLine, -) -> i32 { +) -> i32 +where + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); @@ -330,7 +345,10 @@ unsafe extern "C" fn application_local_command_line( ptr: *mut ffi::GApplication, arguments: *mut *mut *mut c_char, exit_status: *mut i32, -) -> glib::ffi::gboolean { +) -> glib::ffi::gboolean +where + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); @@ -351,32 +369,46 @@ unsafe extern "C" fn application_open( files: *mut *mut ffi::GFile, num_files: i32, hint: *const c_char, -) { +) where + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); let files: Vec = FromGlibContainer::from_glib_none_num(files, num_files as usize); imp.open(files.as_slice(), &glib::GString::from_glib_borrow(hint)) } -unsafe extern "C" fn application_quit_mainloop(ptr: *mut ffi::GApplication) { +unsafe extern "C" fn application_quit_mainloop(ptr: *mut ffi::GApplication) +where + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); imp.quit_mainloop() } -unsafe extern "C" fn application_run_mainloop(ptr: *mut ffi::GApplication) { +unsafe extern "C" fn application_run_mainloop(ptr: *mut ffi::GApplication) +where + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); imp.run_mainloop() } -unsafe extern "C" fn application_shutdown(ptr: *mut ffi::GApplication) { +unsafe extern "C" fn application_shutdown(ptr: *mut ffi::GApplication) +where + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); imp.shutdown() } -unsafe extern "C" fn application_startup(ptr: *mut ffi::GApplication) { +unsafe extern "C" fn application_startup(ptr: *mut ffi::GApplication) +where + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); @@ -386,7 +418,10 @@ unsafe extern "C" fn application_startup(ptr: *mut ffi::GApp unsafe extern "C" fn application_handle_local_options( ptr: *mut ffi::GApplication, options: *mut glib::ffi::GVariantDict, -) -> c_int { +) -> c_int +where + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); diff --git a/gio/src/subclass/async_initable.rs b/gio/src/subclass/async_initable.rs index 1c2171bcfa55..433ae27ac68d 100644 --- a/gio/src/subclass/async_initable.rs +++ b/gio/src/subclass/async_initable.rs @@ -8,7 +8,10 @@ use crate::{ ffi, AsyncInitable, AsyncResult, Cancellable, CancellableFuture, GioFutureResult, LocalTask, }; -pub trait AsyncInitableImpl: ObjectImpl { +pub trait AsyncInitableImpl: ObjectImpl +where + ::Type: IsA, +{ fn init_future( &self, io_priority: glib::Priority, @@ -17,12 +20,10 @@ pub trait AsyncInitableImpl: ObjectImpl { } } -mod sealed { - pub trait Sealed {} - impl Sealed for T {} -} - -pub trait AsyncInitableImplExt: sealed::Sealed + AsyncInitableImpl + ObjectSubclass { +pub trait AsyncInitableImplExt: ObjectSubclass + AsyncInitableImpl +where + ::Type: IsA, +{ fn parent_init_future( &self, io_priority: glib::Priority, @@ -42,6 +43,7 @@ pub trait AsyncInitableImplExt: sealed::Sealed + AsyncInitableImpl + ObjectSubcl user_data: glib::ffi::gpointer, ) where T: AsyncInitableImpl, + ::Type: IsA, { let type_data = T::type_data(); let parent_iface = type_data.as_ref().parent_interface::() @@ -83,9 +85,15 @@ pub trait AsyncInitableImplExt: sealed::Sealed + AsyncInitableImpl + ObjectSubcl } } -impl AsyncInitableImplExt for T {} +impl AsyncInitableImplExt for T where + ::Type: IsA +{ +} -unsafe impl IsImplementable for AsyncInitable { +unsafe impl IsImplementable for AsyncInitable +where + ::Type: IsA, +{ fn interface_init(iface: &mut glib::Interface) { let iface = iface.as_mut(); iface.init_async = Some(async_initable_init_async::); @@ -99,7 +107,9 @@ unsafe extern "C" fn async_initable_init_async( cancellable: *mut ffi::GCancellable, callback: ffi::GAsyncReadyCallback, user_data: glib::ffi::gpointer, -) { +) where + ::Type: IsA, +{ let instance = &*(initable as *mut T::Instance); let imp = instance.imp(); let cancellable = Option::::from_glib_none(cancellable); diff --git a/gio/src/subclass/initable.rs b/gio/src/subclass/initable.rs index 23b4beb7fc8e..9ad33d9bd364 100644 --- a/gio/src/subclass/initable.rs +++ b/gio/src/subclass/initable.rs @@ -6,18 +6,19 @@ use glib::{prelude::*, subclass::prelude::*, translate::*, Error}; use crate::{ffi, Cancellable, Initable}; -pub trait InitableImpl: ObjectImpl { +pub trait InitableImpl: ObjectImpl +where + ::Type: IsA, +{ fn init(&self, cancellable: Option<&Cancellable>) -> Result<(), Error> { self.parent_init(cancellable) } } -mod sealed { - pub trait Sealed {} - impl Sealed for T {} -} - -pub trait InitableImplExt: sealed::Sealed + ObjectSubclass { +pub trait InitableImplExt: ObjectSubclass + InitableImpl +where + ::Type: IsA, +{ fn parent_init(&self, cancellable: Option<&Cancellable>) -> Result<(), Error> { unsafe { let type_data = Self::type_data(); @@ -44,9 +45,12 @@ pub trait InitableImplExt: sealed::Sealed + ObjectSubclass { } } -impl InitableImplExt for T {} +impl InitableImplExt for T where ::Type: IsA {} -unsafe impl IsImplementable for Initable { +unsafe impl IsImplementable for Initable +where + ::Type: IsA, +{ fn interface_init(iface: &mut glib::Interface) { let iface = iface.as_mut(); iface.init = Some(initable_init::); @@ -57,7 +61,10 @@ unsafe extern "C" fn initable_init( initable: *mut ffi::GInitable, cancellable: *mut ffi::GCancellable, error: *mut *mut glib::ffi::GError, -) -> glib::ffi::gboolean { +) -> glib::ffi::gboolean +where + ::Type: IsA, +{ let instance = &*(initable as *mut T::Instance); let imp = instance.imp(); diff --git a/gio/src/subclass/input_stream.rs b/gio/src/subclass/input_stream.rs index e65e27678791..7d8f97c48722 100644 --- a/gio/src/subclass/input_stream.rs +++ b/gio/src/subclass/input_stream.rs @@ -6,7 +6,10 @@ use glib::{prelude::*, subclass::prelude::*, translate::*, Error}; use crate::{ffi, Cancellable, InputStream}; -pub trait InputStreamImpl: ObjectImpl + InputStreamImplExt + Send { +pub trait InputStreamImpl: ObjectImpl + Send +where + ::Type: IsA, +{ fn read(&self, buffer: &mut [u8], cancellable: Option<&Cancellable>) -> Result { self.parent_read(buffer, cancellable) } @@ -20,12 +23,10 @@ pub trait InputStreamImpl: ObjectImpl + InputStreamImplExt + Send { } } -mod sealed { - pub trait Sealed {} - impl Sealed for T {} -} - -pub trait InputStreamImplExt: sealed::Sealed + ObjectSubclass { +pub trait InputStreamImplExt: ObjectSubclass + InputStreamImpl +where + ::Type: IsA, +{ fn parent_read( &self, buffer: &mut [u8], @@ -103,9 +104,13 @@ pub trait InputStreamImplExt: sealed::Sealed + ObjectSubclass { } } -impl InputStreamImplExt for T {} +impl InputStreamImplExt for T where ::Type: IsA +{} -unsafe impl IsSubclassable for InputStream { +unsafe impl IsSubclassable for InputStream +where + ::Type: IsA, +{ fn class_init(class: &mut ::glib::Class) { Self::parent_class_init::(class); @@ -122,7 +127,10 @@ unsafe extern "C" fn stream_read( count: usize, cancellable: *mut ffi::GCancellable, err: *mut *mut glib::ffi::GError, -) -> isize { +) -> isize +where + ::Type: IsA, +{ debug_assert!(count <= isize::MAX as usize); let instance = &*(ptr as *mut T::Instance); @@ -156,7 +164,10 @@ unsafe extern "C" fn stream_close( ptr: *mut ffi::GInputStream, cancellable: *mut ffi::GCancellable, err: *mut *mut glib::ffi::GError, -) -> glib::ffi::gboolean { +) -> glib::ffi::gboolean +where + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); @@ -180,7 +191,10 @@ unsafe extern "C" fn stream_skip( count: usize, cancellable: *mut ffi::GCancellable, err: *mut *mut glib::ffi::GError, -) -> isize { +) -> isize +where + ::Type: IsA, +{ debug_assert!(count <= isize::MAX as usize); let instance = &*(ptr as *mut T::Instance); @@ -299,7 +313,8 @@ mod tests { glib::wrapper! { pub struct SimpleInputStream(ObjectSubclass) - @extends InputStream; + @extends InputStream, + @implements crate::Seekable; } #[test] diff --git a/gio/src/subclass/io_stream.rs b/gio/src/subclass/io_stream.rs index 6a3b290c7049..fed6b9aeb6ca 100644 --- a/gio/src/subclass/io_stream.rs +++ b/gio/src/subclass/io_stream.rs @@ -6,7 +6,10 @@ use glib::{prelude::*, subclass::prelude::*, translate::*, Error}; use crate::{ffi, Cancellable, IOStream, InputStream, OutputStream}; -pub trait IOStreamImpl: ObjectImpl + IOStreamImplExt + Send { +pub trait IOStreamImpl: ObjectImpl + Send +where + ::Type: IsA, +{ fn input_stream(&self) -> InputStream { self.parent_input_stream() } @@ -20,12 +23,10 @@ pub trait IOStreamImpl: ObjectImpl + IOStreamImplExt + Send { } } -mod sealed { - pub trait Sealed {} - impl Sealed for T {} -} - -pub trait IOStreamImplExt: sealed::Sealed + ObjectSubclass { +pub trait IOStreamImplExt: ObjectSubclass + IOStreamImpl +where + ::Type: IsA, +{ fn parent_input_stream(&self) -> InputStream { unsafe { let data = Self::type_data(); @@ -70,9 +71,12 @@ pub trait IOStreamImplExt: sealed::Sealed + ObjectSubclass { } } -impl IOStreamImplExt for T {} +impl IOStreamImplExt for T where ::Type: IsA {} -unsafe impl IsSubclassable for IOStream { +unsafe impl IsSubclassable for IOStream +where + ::Type: IsA, +{ fn class_init(class: &mut ::glib::Class) { Self::parent_class_init::(class); @@ -85,7 +89,10 @@ unsafe impl IsSubclassable for IOStream { unsafe extern "C" fn stream_get_input_stream( ptr: *mut ffi::GIOStream, -) -> *mut ffi::GInputStream { +) -> *mut ffi::GInputStream +where + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); @@ -112,7 +119,10 @@ unsafe extern "C" fn stream_get_input_stream( unsafe extern "C" fn stream_get_output_stream( ptr: *mut ffi::GIOStream, -) -> *mut ffi::GOutputStream { +) -> *mut ffi::GOutputStream +where + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); @@ -141,7 +151,10 @@ unsafe extern "C" fn stream_close( ptr: *mut ffi::GIOStream, cancellable: *mut ffi::GCancellable, err: *mut *mut glib::ffi::GError, -) -> glib::ffi::gboolean { +) -> glib::ffi::gboolean +where + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); diff --git a/gio/src/subclass/list_model.rs b/gio/src/subclass/list_model.rs index 96a411f3595b..8223739d7a6e 100644 --- a/gio/src/subclass/list_model.rs +++ b/gio/src/subclass/list_model.rs @@ -6,7 +6,10 @@ use glib::{prelude::*, subclass::prelude::*, translate::*}; use crate::{ffi, ListModel}; -pub trait ListModelImpl: ObjectImpl { +pub trait ListModelImpl: ObjectImpl +where + ::Type: IsA, +{ #[doc(alias = "get_item_type")] fn item_type(&self) -> glib::Type; #[doc(alias = "get_n_items")] @@ -15,12 +18,10 @@ pub trait ListModelImpl: ObjectImpl { fn item(&self, position: u32) -> Option; } -mod sealed { - pub trait Sealed {} - impl Sealed for T {} -} - -pub trait ListModelImplExt: sealed::Sealed + ObjectSubclass { +pub trait ListModelImplExt: ObjectSubclass + ListModelImpl +where + ::Type: IsA, +{ fn parent_item_type(&self) -> glib::Type { unsafe { let type_data = Self::type_data(); @@ -66,11 +67,11 @@ pub trait ListModelImplExt: sealed::Sealed + ObjectSubclass { } } -impl ListModelImplExt for T {} +impl ListModelImplExt for T where ::Type: IsA {} unsafe impl IsImplementable for ListModel where - ::Type: IsA, + ::Type: IsA, { fn interface_init(iface: &mut glib::Interface) { let iface = iface.as_mut(); @@ -85,7 +86,7 @@ unsafe extern "C" fn list_model_get_item_type( list_model: *mut ffi::GListModel, ) -> glib::ffi::GType where - ::Type: IsA, + ::Type: IsA, { let instance = &*(list_model as *mut T::Instance); let imp = instance.imp(); @@ -117,7 +118,7 @@ unsafe extern "C" fn list_model_get_n_items( list_model: *mut ffi::GListModel, ) -> u32 where - ::Type: IsA, + ::Type: IsA, { let instance = &*(list_model as *mut T::Instance); let imp = instance.imp(); @@ -130,7 +131,7 @@ unsafe extern "C" fn list_model_get_item( position: u32, ) -> *mut glib::gobject_ffi::GObject where - ::Type: IsA, + ::Type: IsA, { let instance = &*(list_model as *mut T::Instance); let imp = instance.imp(); diff --git a/gio/src/subclass/output_stream.rs b/gio/src/subclass/output_stream.rs index 6f9d8ec86c6c..e3836fad748d 100644 --- a/gio/src/subclass/output_stream.rs +++ b/gio/src/subclass/output_stream.rs @@ -6,7 +6,10 @@ use glib::{prelude::*, subclass::prelude::*, translate::*, Error}; use crate::{ffi, Cancellable, InputStream, OutputStream, OutputStreamSpliceFlags}; -pub trait OutputStreamImpl: ObjectImpl + OutputStreamImplExt + Send { +pub trait OutputStreamImpl: ObjectImpl + Send +where + ::Type: IsA, +{ fn write(&self, buffer: &[u8], cancellable: Option<&Cancellable>) -> Result { self.parent_write(buffer, cancellable) } @@ -29,12 +32,10 @@ pub trait OutputStreamImpl: ObjectImpl + OutputStreamImplExt + Send { } } -mod sealed { - pub trait Sealed {} - impl Sealed for T {} -} - -pub trait OutputStreamImplExt: sealed::Sealed + ObjectSubclass { +pub trait OutputStreamImplExt: ObjectSubclass + OutputStreamImpl +where + ::Type: IsA, +{ fn parent_write( &self, buffer: &[u8], @@ -150,9 +151,15 @@ pub trait OutputStreamImplExt: sealed::Sealed + ObjectSubclass { } } -impl OutputStreamImplExt for T {} +impl OutputStreamImplExt for T where + ::Type: IsA +{ +} -unsafe impl IsSubclassable for OutputStream { +unsafe impl IsSubclassable for OutputStream +where + ::Type: IsA, +{ fn class_init(class: &mut ::glib::Class) { Self::parent_class_init::(class); @@ -170,7 +177,10 @@ unsafe extern "C" fn stream_write( count: usize, cancellable: *mut ffi::GCancellable, err: *mut *mut glib::ffi::GError, -) -> isize { +) -> isize +where + ::Type: IsA, +{ debug_assert!(count <= isize::MAX as usize); let instance = &*(ptr as *mut T::Instance); @@ -204,7 +214,10 @@ unsafe extern "C" fn stream_close( ptr: *mut ffi::GOutputStream, cancellable: *mut ffi::GCancellable, err: *mut *mut glib::ffi::GError, -) -> glib::ffi::gboolean { +) -> glib::ffi::gboolean +where + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); @@ -227,7 +240,10 @@ unsafe extern "C" fn stream_flush( ptr: *mut ffi::GOutputStream, cancellable: *mut ffi::GCancellable, err: *mut *mut glib::ffi::GError, -) -> glib::ffi::gboolean { +) -> glib::ffi::gboolean +where + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); @@ -252,7 +268,10 @@ unsafe extern "C" fn stream_splice( flags: ffi::GOutputStreamSpliceFlags, cancellable: *mut ffi::GCancellable, err: *mut *mut glib::ffi::GError, -) -> isize { +) -> isize +where + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); diff --git a/gio/src/subclass/seekable.rs b/gio/src/subclass/seekable.rs index 3d23db1e5a23..dd8a70f2ddeb 100644 --- a/gio/src/subclass/seekable.rs +++ b/gio/src/subclass/seekable.rs @@ -6,7 +6,10 @@ use glib::{prelude::*, subclass::prelude::*, translate::*, Error, SeekType}; use crate::{ffi, Cancellable, Seekable}; -pub trait SeekableImpl: ObjectImpl + Send { +pub trait SeekableImpl: ObjectImpl + Send +where + ::Type: IsA, +{ fn tell(&self) -> i64; fn can_seek(&self) -> bool; fn seek( @@ -19,12 +22,10 @@ pub trait SeekableImpl: ObjectImpl + Send { fn truncate(&self, offset: i64, cancellable: Option<&Cancellable>) -> Result<(), Error>; } -mod sealed { - pub trait Sealed {} - impl Sealed for T {} -} - -pub trait SeekableImplExt: sealed::Sealed + ObjectSubclass { +pub trait SeekableImplExt: ObjectSubclass + SeekableImpl +where + ::Type: IsA, +{ fn parent_tell(&self) -> i64 { unsafe { let type_data = Self::type_data(); @@ -125,9 +126,12 @@ pub trait SeekableImplExt: sealed::Sealed + ObjectSubclass { } } -impl SeekableImplExt for T {} +impl SeekableImplExt for T where ::Type: IsA {} -unsafe impl IsImplementable for Seekable { +unsafe impl IsImplementable for Seekable +where + ::Type: IsA, +{ fn interface_init(iface: &mut glib::Interface) { let iface = iface.as_mut(); @@ -139,7 +143,10 @@ unsafe impl IsImplementable for Seekable { } } -unsafe extern "C" fn seekable_tell(seekable: *mut ffi::GSeekable) -> i64 { +unsafe extern "C" fn seekable_tell(seekable: *mut ffi::GSeekable) -> i64 +where + ::Type: IsA, +{ let instance = &*(seekable as *mut T::Instance); let imp = instance.imp(); @@ -148,7 +155,10 @@ unsafe extern "C" fn seekable_tell(seekable: *mut ffi::GSeekabl unsafe extern "C" fn seekable_can_seek( seekable: *mut ffi::GSeekable, -) -> glib::ffi::gboolean { +) -> glib::ffi::gboolean +where + ::Type: IsA, +{ let instance = &*(seekable as *mut T::Instance); let imp = instance.imp(); @@ -161,7 +171,10 @@ unsafe extern "C" fn seekable_seek( type_: glib::ffi::GSeekType, cancellable: *mut ffi::GCancellable, err: *mut *mut glib::ffi::GError, -) -> glib::ffi::gboolean { +) -> glib::ffi::gboolean +where + ::Type: IsA, +{ let instance = &*(seekable as *mut T::Instance); let imp = instance.imp(); @@ -184,7 +197,10 @@ unsafe extern "C" fn seekable_seek( unsafe extern "C" fn seekable_can_truncate( seekable: *mut ffi::GSeekable, -) -> glib::ffi::gboolean { +) -> glib::ffi::gboolean +where + ::Type: IsA, +{ let instance = &*(seekable as *mut T::Instance); let imp = instance.imp(); @@ -196,7 +212,10 @@ unsafe extern "C" fn seekable_truncate( offset: i64, cancellable: *mut ffi::GCancellable, err: *mut *mut glib::ffi::GError, -) -> glib::ffi::gboolean { +) -> glib::ffi::gboolean +where + ::Type: IsA, +{ let instance = &*(seekable as *mut T::Instance); let imp = instance.imp(); diff --git a/gio/src/subclass/socket_control_message.rs b/gio/src/subclass/socket_control_message.rs index 3f43ac1608e1..6eed7637fb7a 100644 --- a/gio/src/subclass/socket_control_message.rs +++ b/gio/src/subclass/socket_control_message.rs @@ -4,7 +4,10 @@ use glib::{prelude::*, subclass::prelude::*, translate::*}; use crate::{ffi, SocketControlMessage}; -pub trait SocketControlMessageImpl: ObjectImpl + SocketControlMessageImplExt { +pub trait SocketControlMessageImpl: ObjectImpl +where + ::Type: IsA, +{ fn level(&self) -> i32 { self.parent_level() } @@ -26,12 +29,10 @@ pub trait SocketControlMessageImpl: ObjectImpl + SocketControlMessageImplExt { } } -mod sealed { - pub trait Sealed {} - impl Sealed for T {} -} - -pub trait SocketControlMessageImplExt: sealed::Sealed + ObjectSubclass { +pub trait SocketControlMessageImplExt: ObjectSubclass + SocketControlMessageImpl +where + ::Type: IsA, +{ fn parent_level(&self) -> i32 { unsafe { let data = Self::type_data(); @@ -113,9 +114,15 @@ pub trait SocketControlMessageImplExt: sealed::Sealed + ObjectSubclass { } } -impl SocketControlMessageImplExt for T {} +impl SocketControlMessageImplExt for T where + ::Type: IsA +{ +} -unsafe impl IsSubclassable for SocketControlMessage { +unsafe impl IsSubclassable for SocketControlMessage +where + ::Type: IsA, +{ fn class_init(class: &mut ::glib::Class) { Self::parent_class_init::(class); @@ -130,7 +137,10 @@ unsafe impl IsSubclassable for SocketControlMess unsafe extern "C" fn socket_control_message_get_level( ptr: *mut ffi::GSocketControlMessage, -) -> i32 { +) -> i32 +where + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); @@ -139,7 +149,10 @@ unsafe extern "C" fn socket_control_message_get_level( ptr: *mut ffi::GSocketControlMessage, -) -> i32 { +) -> i32 +where + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); @@ -148,7 +161,10 @@ unsafe extern "C" fn socket_control_message_get_type( ptr: *mut ffi::GSocketControlMessage, -) -> usize { +) -> usize +where + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); @@ -158,7 +174,9 @@ unsafe extern "C" fn socket_control_message_get_size( ptr: *mut ffi::GSocketControlMessage, data: glib::ffi::gpointer, -) { +) where + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); @@ -172,7 +190,10 @@ unsafe extern "C" fn socket_control_message_deserialize *mut ffi::GSocketControlMessage { +) -> *mut ffi::GSocketControlMessage +where + ::Type: IsA, +{ let data = std::slice::from_raw_parts(data as *mut u8, size); T::deserialize(level, type_, data).into_glib_ptr() diff --git a/glib/src/gobject/dynamic_object.rs b/glib/src/gobject/dynamic_object.rs index f6e7648046fb..8736aa8ec580 100644 --- a/glib/src/gobject/dynamic_object.rs +++ b/glib/src/gobject/dynamic_object.rs @@ -44,6 +44,7 @@ pub trait DynamicObjectRegisterExt: AsRef + sealed::Sealed + 'static impl + ObjectSubclassIsExt> DynamicObjectRegisterExt for O where O::Subclass: TypePluginRegisterImpl, + ::Type: IsA, { fn add_dynamic_interface( &self, diff --git a/glib/src/subclass/object.rs b/glib/src/subclass/object.rs index ae84380a48f7..fc4b42b6cff7 100644 --- a/glib/src/subclass/object.rs +++ b/glib/src/subclass/object.rs @@ -19,7 +19,7 @@ use crate::{ /// /// This allows overriding the virtual methods of `glib::Object`. Except for /// `finalize` as implementing `Drop` would allow the same behavior. -pub trait ObjectImpl: ObjectSubclass + ObjectImplExt { +pub trait ObjectImpl: ObjectSubclass { // rustdoc-stripper-ignore-next /// Properties installed for this type. fn properties() -> &'static [ParamSpec] { @@ -253,12 +253,7 @@ unsafe impl IsSubclassable for Object { fn instance_init(_instance: &mut super::InitializingObject) {} } -mod sealed { - pub trait Sealed {} - impl Sealed for T {} -} - -pub trait ObjectImplExt: sealed::Sealed + ObjectSubclass { +pub trait ObjectImplExt: ObjectSubclass + ObjectImpl { // rustdoc-stripper-ignore-next /// Chain up to the parent class' implementation of `glib::Object::constructed()`. #[inline] diff --git a/glib/src/subclass/type_module.rs b/glib/src/subclass/type_module.rs index bb0fe6f78ce8..cd78adade1ab 100644 --- a/glib/src/subclass/type_module.rs +++ b/glib/src/subclass/type_module.rs @@ -2,7 +2,10 @@ use crate::{ffi, gobject_ffi, prelude::*, subclass::prelude::*, translate::*, TypeModule}; -pub trait TypeModuleImpl: ObjectImpl + TypeModuleImplExt { +pub trait TypeModuleImpl: ObjectImpl +where + ::Type: IsA, +{ // rustdoc-stripper-ignore-next /// Loads the module, registers one or more object subclasses using /// [`register_dynamic_type`] and registers one or more object interfaces @@ -21,12 +24,18 @@ pub trait TypeModuleImpl: ObjectImpl + TypeModuleImplExt { fn unload(&self); } -pub trait TypeModuleImplExt: ObjectSubclass { +pub trait TypeModuleImplExt: ObjectSubclass + TypeModuleImpl +where + ::Type: IsA, +{ fn parent_load(&self) -> bool; fn parent_unload(&self); } -impl TypeModuleImplExt for T { +impl TypeModuleImplExt for T +where + ::Type: IsA, +{ fn parent_load(&self) -> bool { unsafe { let data = T::type_data(); @@ -58,7 +67,10 @@ impl TypeModuleImplExt for T { } } -unsafe impl IsSubclassable for TypeModule { +unsafe impl IsSubclassable for TypeModule +where + ::Type: IsA, +{ fn class_init(class: &mut crate::Class) { Self::parent_class_init::(class); @@ -70,7 +82,10 @@ unsafe impl IsSubclassable for TypeModule { unsafe extern "C" fn load( type_module: *mut gobject_ffi::GTypeModule, -) -> ffi::gboolean { +) -> ffi::gboolean +where + ::Type: IsA, +{ let instance = &*(type_module as *mut T::Instance); let imp = instance.imp(); @@ -90,7 +105,10 @@ unsafe extern "C" fn load( res.into_glib() } -unsafe extern "C" fn unload(type_module: *mut gobject_ffi::GTypeModule) { +unsafe extern "C" fn unload(type_module: *mut gobject_ffi::GTypeModule) +where + ::Type: IsA, +{ let instance = &*(type_module as *mut T::Instance); let imp = instance.imp(); diff --git a/glib/src/subclass/type_plugin.rs b/glib/src/subclass/type_plugin.rs index bb4d755f8a88..9e8ab6908b0a 100644 --- a/glib/src/subclass/type_plugin.rs +++ b/glib/src/subclass/type_plugin.rs @@ -6,7 +6,10 @@ use crate::{ Type, TypeFlags, TypeInfo, TypePlugin, TypeValueTable, }; -pub trait TypePluginImpl: ObjectImpl + TypePluginImplExt { +pub trait TypePluginImpl: ObjectImpl +where + ::Type: IsA, +{ fn use_plugin(&self) { self.parent_use_plugin(); } @@ -24,7 +27,10 @@ pub trait TypePluginImpl: ObjectImpl + TypePluginImplExt { } } -pub trait TypePluginImplExt: ObjectSubclass { +pub trait TypePluginImplExt: ObjectSubclass + TypePluginImpl +where + ::Type: IsA, +{ fn parent_use_plugin(&self); fn parent_unuse_plugin(&self); fn parent_complete_type_info(&self, type_: Type) -> (TypeInfo, TypeValueTable); @@ -35,7 +41,10 @@ pub trait TypePluginImplExt: ObjectSubclass { ) -> InterfaceInfo; } -impl TypePluginImplExt for T { +impl TypePluginImplExt for T +where + ::Type: IsA, +{ fn parent_use_plugin(&self) { unsafe { let type_data = Self::type_data(); @@ -113,7 +122,10 @@ impl TypePluginImplExt for T { } } -unsafe impl IsImplementable for TypePlugin { +unsafe impl IsImplementable for TypePlugin +where + ::Type: IsA, +{ fn interface_init(iface: &mut Interface) { let iface = iface.as_mut(); @@ -124,14 +136,20 @@ unsafe impl IsImplementable for TypePlugin { } } -unsafe extern "C" fn use_plugin(type_plugin: *mut gobject_ffi::GTypePlugin) { +unsafe extern "C" fn use_plugin(type_plugin: *mut gobject_ffi::GTypePlugin) +where + ::Type: IsA, +{ let instance = &*(type_plugin as *mut T::Instance); let imp = instance.imp(); imp.use_plugin(); } -unsafe extern "C" fn unuse_plugin(type_plugin: *mut gobject_ffi::GTypePlugin) { +unsafe extern "C" fn unuse_plugin(type_plugin: *mut gobject_ffi::GTypePlugin) +where + ::Type: IsA, +{ let instance = &*(type_plugin as *mut T::Instance); let imp = instance.imp(); @@ -143,7 +161,9 @@ unsafe extern "C" fn complete_type_info( gtype: ffi::GType, info_ptr: *mut gobject_ffi::GTypeInfo, value_table_ptr: *mut gobject_ffi::GTypeValueTable, -) { +) where + ::Type: IsA, +{ assert!(!info_ptr.is_null()); assert!(!value_table_ptr.is_null()); let instance = &*(type_plugin as *mut T::Instance); @@ -163,7 +183,9 @@ unsafe extern "C" fn complete_interface_info( instance_gtype: ffi::GType, interface_gtype: ffi::GType, info_ptr: *mut gobject_ffi::GInterfaceInfo, -) { +) where + ::Type: IsA, +{ assert!(!info_ptr.is_null()); let instance = &*(type_plugin as *mut T::Instance); let imp = instance.imp(); @@ -175,7 +197,10 @@ unsafe extern "C" fn complete_interface_info( *info = info_; } -pub trait TypePluginRegisterImpl: ObjectImpl + TypePluginImpl { +pub trait TypePluginRegisterImpl: ObjectImpl + TypePluginImpl +where + ::Type: IsA, +{ fn add_dynamic_interface( &self, _instance_type: Type, From 07dbf348f042fcc7c071035b5834ce0731ae9996 Mon Sep 17 00:00:00 2001 From: Fina Wilke Date: Sun, 29 Sep 2024 20:00:29 +0200 Subject: [PATCH 2/3] Add IsA trait bound to Impl traits --- gdk-pixbuf/src/subclass/pixbuf_animation.rs | 13 ++- .../src/subclass/pixbuf_animation_iter.rs | 13 ++- gdk-pixbuf/src/subclass/pixbuf_loader.rs | 13 ++- gio/src/subclass/action_group.rs | 25 ++++- gio/src/subclass/action_map.rs | 13 ++- gio/src/subclass/application.rs | 22 ++++- gio/src/subclass/async_initable.rs | 11 ++- gio/src/subclass/initable.rs | 11 ++- gio/src/subclass/input_stream.rs | 14 ++- gio/src/subclass/io_stream.rs | 13 ++- gio/src/subclass/list_model.rs | 13 ++- gio/src/subclass/output_stream.rs | 13 ++- gio/src/subclass/seekable.rs | 15 ++- gio/src/subclass/socket_control_message.rs | 14 ++- glib-macros/tests/object_subclass_dynamic.rs | 92 ++++++++++++++++--- glib-macros/tests/properties.rs | 5 +- glib/src/gobject/dynamic_object.rs | 3 +- glib/src/subclass/object.rs | 43 +++++++-- glib/src/subclass/type_module.rs | 8 +- glib/src/subclass/type_plugin.rs | 11 ++- ...04-auto-send-sync-with-send-sync-parent.rs | 11 ++- ...uto-send-sync-with-non-send-sync-parent.rs | 11 ++- ...send-sync-with-non-send-sync-parent.stderr | 12 +-- ...send-sync-with-non-send-sync-ffi-parent.rs | 10 +- ...-sync-with-non-send-sync-ffi-parent.stderr | 24 ++--- 25 files changed, 356 insertions(+), 77 deletions(-) diff --git a/gdk-pixbuf/src/subclass/pixbuf_animation.rs b/gdk-pixbuf/src/subclass/pixbuf_animation.rs index ee5ff297496d..ae08ed4ede66 100644 --- a/gdk-pixbuf/src/subclass/pixbuf_animation.rs +++ b/gdk-pixbuf/src/subclass/pixbuf_animation.rs @@ -15,6 +15,7 @@ use crate::{ffi, Pixbuf, PixbufAnimation, PixbufAnimationIter}; pub trait PixbufAnimationImpl: ObjectImpl where + ::Type: IsA, ::Type: IsA, { fn is_static_image(&self) -> bool { @@ -36,6 +37,7 @@ where pub trait PixbufAnimationImplExt: ObjectSubclass + PixbufAnimationImpl where + ::Type: IsA, ::Type: IsA, { fn parent_is_static_image(&self) -> bool { @@ -117,13 +119,16 @@ where } } -impl PixbufAnimationImplExt for T where - ::Type: IsA +impl PixbufAnimationImplExt for T +where + ::Type: IsA, + ::Type: IsA, { } unsafe impl IsSubclassable for PixbufAnimation where + ::Type: IsA, ::Type: IsA, { fn class_init(class: &mut ::glib::Class) { @@ -141,6 +146,7 @@ unsafe extern "C" fn animation_is_static_image( ptr: *mut ffi::GdkPixbufAnimation, ) -> glib::ffi::gboolean where + ::Type: IsA, ::Type: IsA, { let instance = &*(ptr as *mut T::Instance); @@ -154,6 +160,7 @@ unsafe extern "C" fn animation_get_size( width_ptr: *mut libc::c_int, height_ptr: *mut libc::c_int, ) where + ::Type: IsA, ::Type: IsA, { if width_ptr.is_null() && height_ptr.is_null() { @@ -176,6 +183,7 @@ unsafe extern "C" fn animation_get_static_image( ptr: *mut ffi::GdkPixbufAnimation, ) -> *mut ffi::GdkPixbuf where + ::Type: IsA, ::Type: IsA, { let instance = &*(ptr as *mut T::Instance); @@ -209,6 +217,7 @@ unsafe extern "C" fn animation_get_iter( start_time_ptr: *const glib::ffi::GTimeVal, ) -> *mut ffi::GdkPixbufAnimationIter where + ::Type: IsA, ::Type: IsA, { let instance = &*(ptr as *mut T::Instance); diff --git a/gdk-pixbuf/src/subclass/pixbuf_animation_iter.rs b/gdk-pixbuf/src/subclass/pixbuf_animation_iter.rs index 03e16a1db22c..d3a104a2e8b8 100644 --- a/gdk-pixbuf/src/subclass/pixbuf_animation_iter.rs +++ b/gdk-pixbuf/src/subclass/pixbuf_animation_iter.rs @@ -14,6 +14,7 @@ use crate::{ffi, Pixbuf, PixbufAnimationIter}; pub trait PixbufAnimationIterImpl: ObjectImpl where + ::Type: IsA, ::Type: IsA, { // rustdoc-stripper-ignore-next @@ -37,6 +38,7 @@ where pub trait PixbufAnimationIterImplExt: ObjectSubclass + PixbufAnimationIterImpl where + ::Type: IsA, ::Type: IsA, { fn parent_delay_time(&self) -> Option { @@ -122,13 +124,16 @@ where } } -impl PixbufAnimationIterImplExt for T where - ::Type: IsA +impl PixbufAnimationIterImplExt for T +where + ::Type: IsA, + ::Type: IsA, { } unsafe impl IsSubclassable for PixbufAnimationIter where + ::Type: IsA, ::Type: IsA, { fn class_init(class: &mut ::glib::Class) { @@ -146,6 +151,7 @@ unsafe extern "C" fn animation_iter_get_delay_time( ptr: *mut ffi::GdkPixbufAnimationIter, ) -> i32 where + ::Type: IsA, ::Type: IsA, { let instance = &*(ptr as *mut T::Instance); @@ -158,6 +164,7 @@ unsafe extern "C" fn animation_iter_get_pixbuf( ptr: *mut ffi::GdkPixbufAnimationIter, ) -> *mut ffi::GdkPixbuf where + ::Type: IsA, ::Type: IsA, { let instance = &*(ptr as *mut T::Instance); @@ -177,6 +184,7 @@ unsafe extern "C" fn animation_iter_on_currently_loading_frame glib::ffi::gboolean where + ::Type: IsA, ::Type: IsA, { let instance = &*(ptr as *mut T::Instance); @@ -190,6 +198,7 @@ unsafe extern "C" fn animation_iter_advance( current_time_ptr: *const glib::ffi::GTimeVal, ) -> glib::ffi::gboolean where + ::Type: IsA, ::Type: IsA, { let instance = &*(ptr as *mut T::Instance); diff --git a/gdk-pixbuf/src/subclass/pixbuf_loader.rs b/gdk-pixbuf/src/subclass/pixbuf_loader.rs index e99388644043..a1b7b0d12175 100644 --- a/gdk-pixbuf/src/subclass/pixbuf_loader.rs +++ b/gdk-pixbuf/src/subclass/pixbuf_loader.rs @@ -9,6 +9,7 @@ use crate::{ffi, PixbufLoader}; pub trait PixbufLoaderImpl: ObjectImpl where + ::Type: IsA, ::Type: IsA, { fn size_prepared(&self, width: i32, height: i32) { @@ -30,6 +31,7 @@ where pub trait PixbufLoaderImplExt: ObjectSubclass + PixbufLoaderImpl where + ::Type: IsA, ::Type: IsA, { fn parent_size_prepared(&self, width: i32, height: i32) { @@ -97,13 +99,16 @@ where } } -impl PixbufLoaderImplExt for T where - ::Type: IsA +impl PixbufLoaderImplExt for T +where + ::Type: IsA, + ::Type: IsA, { } unsafe impl IsSubclassable for PixbufLoader where + ::Type: IsA, ::Type: IsA, { fn class_init(class: &mut ::glib::Class) { @@ -122,6 +127,7 @@ unsafe extern "C" fn loader_size_prepared( width: i32, height: i32, ) where + ::Type: IsA, ::Type: IsA, { let instance = &*(ptr as *mut T::Instance); @@ -132,6 +138,7 @@ unsafe extern "C" fn loader_size_prepared( unsafe extern "C" fn loader_area_prepared(ptr: *mut ffi::GdkPixbufLoader) where + ::Type: IsA, ::Type: IsA, { let instance = &*(ptr as *mut T::Instance); @@ -147,6 +154,7 @@ unsafe extern "C" fn loader_area_updated( width: i32, height: i32, ) where + ::Type: IsA, ::Type: IsA, { let instance = &*(ptr as *mut T::Instance); @@ -157,6 +165,7 @@ unsafe extern "C" fn loader_area_updated( unsafe extern "C" fn loader_closed(ptr: *mut ffi::GdkPixbufLoader) where + ::Type: IsA, ::Type: IsA, { let instance = &*(ptr as *mut T::Instance); diff --git a/gio/src/subclass/action_group.rs b/gio/src/subclass/action_group.rs index ca895077889a..69fd5168ef65 100644 --- a/gio/src/subclass/action_group.rs +++ b/gio/src/subclass/action_group.rs @@ -8,6 +8,7 @@ use crate::{ffi, ActionGroup}; pub trait ActionGroupImpl: ObjectImpl where + ::Type: IsA, ::Type: IsA, { fn action_added(&self, action_name: &str) { @@ -78,6 +79,7 @@ where pub trait ActionGroupImplExt: ObjectSubclass + ActionGroupImpl where + ::Type: IsA, ::Type: IsA, { fn parent_action_added(&self, action_name: &str) { @@ -342,11 +344,16 @@ where } } -impl ActionGroupImplExt for T where ::Type: IsA -{} +impl ActionGroupImplExt for T +where + ::Type: IsA, + ::Type: IsA, +{ +} unsafe impl IsImplementable for ActionGroup where + ::Type: IsA, ::Type: IsA, { fn interface_init(iface: &mut glib::Interface) { @@ -374,6 +381,7 @@ unsafe extern "C" fn action_group_has_action( action_nameptr: *const libc::c_char, ) -> glib::ffi::gboolean where + ::Type: IsA, ::Type: IsA, { let instance = &*(action_group as *mut T::Instance); @@ -388,6 +396,7 @@ unsafe extern "C" fn action_group_get_action_enabled( action_nameptr: *const libc::c_char, ) -> glib::ffi::gboolean where + ::Type: IsA, ::Type: IsA, { let instance = &*(action_group as *mut T::Instance); @@ -412,6 +421,7 @@ unsafe extern "C" fn action_group_get_action_parameter_type( action_nameptr: *const libc::c_char, ) -> *const glib::ffi::GVariantType where + ::Type: IsA, ::Type: IsA, { let instance = &*(action_group as *mut T::Instance); @@ -444,6 +454,7 @@ unsafe extern "C" fn action_group_get_action_state_type( action_nameptr: *const libc::c_char, ) -> *const glib::ffi::GVariantType where + ::Type: IsA, ::Type: IsA, { let instance = &*(action_group as *mut T::Instance); @@ -476,6 +487,7 @@ unsafe extern "C" fn action_group_get_action_state_hint( action_nameptr: *const libc::c_char, ) -> *mut glib::ffi::GVariant where + ::Type: IsA, ::Type: IsA, { let instance = &*(action_group as *mut T::Instance); @@ -507,6 +519,7 @@ unsafe extern "C" fn action_group_get_action_state( action_nameptr: *const libc::c_char, ) -> *mut glib::ffi::GVariant where + ::Type: IsA, ::Type: IsA, { let instance = &*(action_group as *mut T::Instance); @@ -536,6 +549,7 @@ unsafe extern "C" fn action_group_change_action_state( action_nameptr: *const libc::c_char, stateptr: *mut glib::ffi::GVariant, ) where + ::Type: IsA, ::Type: IsA, { let instance = &*(action_group as *mut T::Instance); @@ -551,6 +565,7 @@ unsafe extern "C" fn action_group_activate_action( action_nameptr: *const libc::c_char, parameterptr: *mut glib::ffi::GVariant, ) where + ::Type: IsA, ::Type: IsA, { let instance = &*(action_group as *mut T::Instance); @@ -565,6 +580,7 @@ unsafe extern "C" fn action_group_action_added( action_group: *mut ffi::GActionGroup, action_nameptr: *const libc::c_char, ) where + ::Type: IsA, ::Type: IsA, { let instance = &*(action_group as *mut T::Instance); @@ -578,6 +594,7 @@ unsafe extern "C" fn action_group_action_removed( action_group: *mut ffi::GActionGroup, action_nameptr: *const libc::c_char, ) where + ::Type: IsA, ::Type: IsA, { let instance = &*(action_group as *mut T::Instance); @@ -592,6 +609,7 @@ unsafe extern "C" fn action_group_action_enabled_changed( action_nameptr: *const libc::c_char, enabled: glib::ffi::gboolean, ) where + ::Type: IsA, ::Type: IsA, { let instance = &*(action_group as *mut T::Instance); @@ -606,6 +624,7 @@ unsafe extern "C" fn action_group_action_state_changed( action_nameptr: *const libc::c_char, stateptr: *mut glib::ffi::GVariant, ) where + ::Type: IsA, ::Type: IsA, { let instance = &*(action_group as *mut T::Instance); @@ -620,6 +639,7 @@ unsafe extern "C" fn action_group_list_actions( action_group: *mut ffi::GActionGroup, ) -> *mut *mut libc::c_char where + ::Type: IsA, ::Type: IsA, { let instance = &*(action_group as *mut T::Instance); @@ -649,6 +669,7 @@ unsafe extern "C" fn action_group_query_action( state: *mut *mut glib::ffi::GVariant, ) -> glib::ffi::gboolean where + ::Type: IsA, ::Type: IsA, { let instance = &*(action_group as *mut T::Instance); diff --git a/gio/src/subclass/action_map.rs b/gio/src/subclass/action_map.rs index 13b21ca01afc..6a30d68ec107 100644 --- a/gio/src/subclass/action_map.rs +++ b/gio/src/subclass/action_map.rs @@ -8,6 +8,7 @@ use crate::{ffi, Action, ActionMap}; pub trait ActionMapImpl: ObjectImpl where + ::Type: IsA, ::Type: IsA, { fn lookup_action(&self, action_name: &str) -> Option; @@ -17,6 +18,7 @@ where pub trait ActionMapImplExt: ObjectSubclass + ActionMapImpl where + ::Type: IsA, ::Type: IsA, { fn parent_lookup_action(&self, name: &str) -> Option { @@ -69,10 +71,16 @@ where } } -impl ActionMapImplExt for T where ::Type: IsA {} +impl ActionMapImplExt for T +where + ::Type: IsA, + ::Type: IsA, +{ +} unsafe impl IsImplementable for ActionMap where + ::Type: IsA, ::Type: IsA, { fn interface_init(iface: &mut glib::Interface) { @@ -89,6 +97,7 @@ unsafe extern "C" fn action_map_lookup_action( action_nameptr: *const libc::c_char, ) -> *mut ffi::GAction where + ::Type: IsA, ::Type: IsA, { let instance = &*(action_map as *mut T::Instance); @@ -121,6 +130,7 @@ unsafe extern "C" fn action_map_add_action( action_map: *mut ffi::GActionMap, actionptr: *mut ffi::GAction, ) where + ::Type: IsA, ::Type: IsA, { let instance = &*(action_map as *mut T::Instance); @@ -134,6 +144,7 @@ unsafe extern "C" fn action_map_remove_action( action_map: *mut ffi::GActionMap, action_nameptr: *const libc::c_char, ) where + ::Type: IsA, ::Type: IsA, { let instance = &*(action_map as *mut T::Instance); diff --git a/gio/src/subclass/application.rs b/gio/src/subclass/application.rs index b9962f15078d..bee49e117bed 100644 --- a/gio/src/subclass/application.rs +++ b/gio/src/subclass/application.rs @@ -66,6 +66,7 @@ impl From for Vec { pub trait ApplicationImpl: ObjectImpl where + ::Type: IsA, ::Type: IsA, { fn activate(&self) { @@ -115,6 +116,7 @@ where pub trait ApplicationImplExt: ObjectSubclass + ApplicationImpl where + ::Type: IsA, ::Type: IsA, { fn parent_activate(&self) { @@ -272,11 +274,16 @@ where } } -impl ApplicationImplExt for T where ::Type: IsA -{} +impl ApplicationImplExt for T +where + ::Type: IsA, + ::Type: IsA, +{ +} unsafe impl IsSubclassable for Application where + ::Type: IsA, ::Type: IsA, { fn class_init(class: &mut ::glib::Class) { @@ -299,6 +306,7 @@ where unsafe extern "C" fn application_activate(ptr: *mut ffi::GApplication) where + ::Type: IsA, ::Type: IsA, { let instance = &*(ptr as *mut T::Instance); @@ -311,6 +319,7 @@ unsafe extern "C" fn application_after_emit( ptr: *mut ffi::GApplication, platform_data: *mut glib::ffi::GVariant, ) where + ::Type: IsA, ::Type: IsA, { let instance = &*(ptr as *mut T::Instance); @@ -322,6 +331,7 @@ unsafe extern "C" fn application_before_emit( ptr: *mut ffi::GApplication, platform_data: *mut glib::ffi::GVariant, ) where + ::Type: IsA, ::Type: IsA, { let instance = &*(ptr as *mut T::Instance); @@ -334,6 +344,7 @@ unsafe extern "C" fn application_command_line( command_line: *mut ffi::GApplicationCommandLine, ) -> i32 where + ::Type: IsA, ::Type: IsA, { let instance = &*(ptr as *mut T::Instance); @@ -347,6 +358,7 @@ unsafe extern "C" fn application_local_command_line( exit_status: *mut i32, ) -> glib::ffi::gboolean where + ::Type: IsA, ::Type: IsA, { let instance = &*(ptr as *mut T::Instance); @@ -370,6 +382,7 @@ unsafe extern "C" fn application_open( num_files: i32, hint: *const c_char, ) where + ::Type: IsA, ::Type: IsA, { let instance = &*(ptr as *mut T::Instance); @@ -380,6 +393,7 @@ unsafe extern "C" fn application_open( } unsafe extern "C" fn application_quit_mainloop(ptr: *mut ffi::GApplication) where + ::Type: IsA, ::Type: IsA, { let instance = &*(ptr as *mut T::Instance); @@ -389,6 +403,7 @@ where } unsafe extern "C" fn application_run_mainloop(ptr: *mut ffi::GApplication) where + ::Type: IsA, ::Type: IsA, { let instance = &*(ptr as *mut T::Instance); @@ -398,6 +413,7 @@ where } unsafe extern "C" fn application_shutdown(ptr: *mut ffi::GApplication) where + ::Type: IsA, ::Type: IsA, { let instance = &*(ptr as *mut T::Instance); @@ -407,6 +423,7 @@ where } unsafe extern "C" fn application_startup(ptr: *mut ffi::GApplication) where + ::Type: IsA, ::Type: IsA, { let instance = &*(ptr as *mut T::Instance); @@ -420,6 +437,7 @@ unsafe extern "C" fn application_handle_local_options( options: *mut glib::ffi::GVariantDict, ) -> c_int where + ::Type: IsA, ::Type: IsA, { let instance = &*(ptr as *mut T::Instance); diff --git a/gio/src/subclass/async_initable.rs b/gio/src/subclass/async_initable.rs index 433ae27ac68d..07e36151f943 100644 --- a/gio/src/subclass/async_initable.rs +++ b/gio/src/subclass/async_initable.rs @@ -10,6 +10,7 @@ use crate::{ pub trait AsyncInitableImpl: ObjectImpl where + ::Type: IsA, ::Type: IsA, { fn init_future( @@ -22,6 +23,7 @@ where pub trait AsyncInitableImplExt: ObjectSubclass + AsyncInitableImpl where + ::Type: IsA, ::Type: IsA, { fn parent_init_future( @@ -43,6 +45,7 @@ where user_data: glib::ffi::gpointer, ) where T: AsyncInitableImpl, + ::Type: IsA, ::Type: IsA, { let type_data = T::type_data(); @@ -85,13 +88,16 @@ where } } -impl AsyncInitableImplExt for T where - ::Type: IsA +impl AsyncInitableImplExt for T +where + ::Type: IsA, + ::Type: IsA, { } unsafe impl IsImplementable for AsyncInitable where + ::Type: IsA, ::Type: IsA, { fn interface_init(iface: &mut glib::Interface) { @@ -108,6 +114,7 @@ unsafe extern "C" fn async_initable_init_async( callback: ffi::GAsyncReadyCallback, user_data: glib::ffi::gpointer, ) where + ::Type: IsA, ::Type: IsA, { let instance = &*(initable as *mut T::Instance); diff --git a/gio/src/subclass/initable.rs b/gio/src/subclass/initable.rs index 9ad33d9bd364..4c83a6a89667 100644 --- a/gio/src/subclass/initable.rs +++ b/gio/src/subclass/initable.rs @@ -8,6 +8,7 @@ use crate::{ffi, Cancellable, Initable}; pub trait InitableImpl: ObjectImpl where + ::Type: IsA, ::Type: IsA, { fn init(&self, cancellable: Option<&Cancellable>) -> Result<(), Error> { @@ -17,6 +18,7 @@ where pub trait InitableImplExt: ObjectSubclass + InitableImpl where + ::Type: IsA, ::Type: IsA, { fn parent_init(&self, cancellable: Option<&Cancellable>) -> Result<(), Error> { @@ -45,10 +47,16 @@ where } } -impl InitableImplExt for T where ::Type: IsA {} +impl InitableImplExt for T +where + ::Type: IsA, + ::Type: IsA, +{ +} unsafe impl IsImplementable for Initable where + ::Type: IsA, ::Type: IsA, { fn interface_init(iface: &mut glib::Interface) { @@ -63,6 +71,7 @@ unsafe extern "C" fn initable_init( error: *mut *mut glib::ffi::GError, ) -> glib::ffi::gboolean where + ::Type: IsA, ::Type: IsA, { let instance = &*(initable as *mut T::Instance); diff --git a/gio/src/subclass/input_stream.rs b/gio/src/subclass/input_stream.rs index 7d8f97c48722..67295120e520 100644 --- a/gio/src/subclass/input_stream.rs +++ b/gio/src/subclass/input_stream.rs @@ -8,6 +8,7 @@ use crate::{ffi, Cancellable, InputStream}; pub trait InputStreamImpl: ObjectImpl + Send where + ::Type: IsA, ::Type: IsA, { fn read(&self, buffer: &mut [u8], cancellable: Option<&Cancellable>) -> Result { @@ -25,6 +26,7 @@ where pub trait InputStreamImplExt: ObjectSubclass + InputStreamImpl where + ::Type: IsA, ::Type: IsA, { fn parent_read( @@ -104,11 +106,16 @@ where } } -impl InputStreamImplExt for T where ::Type: IsA -{} +impl InputStreamImplExt for T +where + ::Type: IsA, + ::Type: IsA, +{ +} unsafe impl IsSubclassable for InputStream where + ::Type: IsA, ::Type: IsA, { fn class_init(class: &mut ::glib::Class) { @@ -129,6 +136,7 @@ unsafe extern "C" fn stream_read( err: *mut *mut glib::ffi::GError, ) -> isize where + ::Type: IsA, ::Type: IsA, { debug_assert!(count <= isize::MAX as usize); @@ -166,6 +174,7 @@ unsafe extern "C" fn stream_close( err: *mut *mut glib::ffi::GError, ) -> glib::ffi::gboolean where + ::Type: IsA, ::Type: IsA, { let instance = &*(ptr as *mut T::Instance); @@ -193,6 +202,7 @@ unsafe extern "C" fn stream_skip( err: *mut *mut glib::ffi::GError, ) -> isize where + ::Type: IsA, ::Type: IsA, { debug_assert!(count <= isize::MAX as usize); diff --git a/gio/src/subclass/io_stream.rs b/gio/src/subclass/io_stream.rs index fed6b9aeb6ca..193ab49a979e 100644 --- a/gio/src/subclass/io_stream.rs +++ b/gio/src/subclass/io_stream.rs @@ -8,6 +8,7 @@ use crate::{ffi, Cancellable, IOStream, InputStream, OutputStream}; pub trait IOStreamImpl: ObjectImpl + Send where + ::Type: IsA, ::Type: IsA, { fn input_stream(&self) -> InputStream { @@ -25,6 +26,7 @@ where pub trait IOStreamImplExt: ObjectSubclass + IOStreamImpl where + ::Type: IsA, ::Type: IsA, { fn parent_input_stream(&self) -> InputStream { @@ -71,10 +73,16 @@ where } } -impl IOStreamImplExt for T where ::Type: IsA {} +impl IOStreamImplExt for T +where + ::Type: IsA, + ::Type: IsA, +{ +} unsafe impl IsSubclassable for IOStream where + ::Type: IsA, ::Type: IsA, { fn class_init(class: &mut ::glib::Class) { @@ -91,6 +99,7 @@ unsafe extern "C" fn stream_get_input_stream( ptr: *mut ffi::GIOStream, ) -> *mut ffi::GInputStream where + ::Type: IsA, ::Type: IsA, { let instance = &*(ptr as *mut T::Instance); @@ -121,6 +130,7 @@ unsafe extern "C" fn stream_get_output_stream( ptr: *mut ffi::GIOStream, ) -> *mut ffi::GOutputStream where + ::Type: IsA, ::Type: IsA, { let instance = &*(ptr as *mut T::Instance); @@ -153,6 +163,7 @@ unsafe extern "C" fn stream_close( err: *mut *mut glib::ffi::GError, ) -> glib::ffi::gboolean where + ::Type: IsA, ::Type: IsA, { let instance = &*(ptr as *mut T::Instance); diff --git a/gio/src/subclass/list_model.rs b/gio/src/subclass/list_model.rs index 8223739d7a6e..ebe0d4b7f9f5 100644 --- a/gio/src/subclass/list_model.rs +++ b/gio/src/subclass/list_model.rs @@ -8,6 +8,7 @@ use crate::{ffi, ListModel}; pub trait ListModelImpl: ObjectImpl where + ::Type: IsA, ::Type: IsA, { #[doc(alias = "get_item_type")] @@ -20,6 +21,7 @@ where pub trait ListModelImplExt: ObjectSubclass + ListModelImpl where + ::Type: IsA, ::Type: IsA, { fn parent_item_type(&self) -> glib::Type { @@ -67,10 +69,16 @@ where } } -impl ListModelImplExt for T where ::Type: IsA {} +impl ListModelImplExt for T +where + ::Type: IsA, + ::Type: IsA, +{ +} unsafe impl IsImplementable for ListModel where + ::Type: IsA, ::Type: IsA, { fn interface_init(iface: &mut glib::Interface) { @@ -86,6 +94,7 @@ unsafe extern "C" fn list_model_get_item_type( list_model: *mut ffi::GListModel, ) -> glib::ffi::GType where + ::Type: IsA, ::Type: IsA, { let instance = &*(list_model as *mut T::Instance); @@ -118,6 +127,7 @@ unsafe extern "C" fn list_model_get_n_items( list_model: *mut ffi::GListModel, ) -> u32 where + ::Type: IsA, ::Type: IsA, { let instance = &*(list_model as *mut T::Instance); @@ -131,6 +141,7 @@ unsafe extern "C" fn list_model_get_item( position: u32, ) -> *mut glib::gobject_ffi::GObject where + ::Type: IsA, ::Type: IsA, { let instance = &*(list_model as *mut T::Instance); diff --git a/gio/src/subclass/output_stream.rs b/gio/src/subclass/output_stream.rs index e3836fad748d..11e1de18b707 100644 --- a/gio/src/subclass/output_stream.rs +++ b/gio/src/subclass/output_stream.rs @@ -8,6 +8,7 @@ use crate::{ffi, Cancellable, InputStream, OutputStream, OutputStreamSpliceFlags pub trait OutputStreamImpl: ObjectImpl + Send where + ::Type: IsA, ::Type: IsA, { fn write(&self, buffer: &[u8], cancellable: Option<&Cancellable>) -> Result { @@ -34,6 +35,7 @@ where pub trait OutputStreamImplExt: ObjectSubclass + OutputStreamImpl where + ::Type: IsA, ::Type: IsA, { fn parent_write( @@ -151,13 +153,16 @@ where } } -impl OutputStreamImplExt for T where - ::Type: IsA +impl OutputStreamImplExt for T +where + ::Type: IsA, + ::Type: IsA, { } unsafe impl IsSubclassable for OutputStream where + ::Type: IsA, ::Type: IsA, { fn class_init(class: &mut ::glib::Class) { @@ -179,6 +184,7 @@ unsafe extern "C" fn stream_write( err: *mut *mut glib::ffi::GError, ) -> isize where + ::Type: IsA, ::Type: IsA, { debug_assert!(count <= isize::MAX as usize); @@ -216,6 +222,7 @@ unsafe extern "C" fn stream_close( err: *mut *mut glib::ffi::GError, ) -> glib::ffi::gboolean where + ::Type: IsA, ::Type: IsA, { let instance = &*(ptr as *mut T::Instance); @@ -242,6 +249,7 @@ unsafe extern "C" fn stream_flush( err: *mut *mut glib::ffi::GError, ) -> glib::ffi::gboolean where + ::Type: IsA, ::Type: IsA, { let instance = &*(ptr as *mut T::Instance); @@ -270,6 +278,7 @@ unsafe extern "C" fn stream_splice( err: *mut *mut glib::ffi::GError, ) -> isize where + ::Type: IsA, ::Type: IsA, { let instance = &*(ptr as *mut T::Instance); diff --git a/gio/src/subclass/seekable.rs b/gio/src/subclass/seekable.rs index dd8a70f2ddeb..d713e20302c0 100644 --- a/gio/src/subclass/seekable.rs +++ b/gio/src/subclass/seekable.rs @@ -8,6 +8,7 @@ use crate::{ffi, Cancellable, Seekable}; pub trait SeekableImpl: ObjectImpl + Send where + ::Type: IsA, ::Type: IsA, { fn tell(&self) -> i64; @@ -24,6 +25,7 @@ where pub trait SeekableImplExt: ObjectSubclass + SeekableImpl where + ::Type: IsA, ::Type: IsA, { fn parent_tell(&self) -> i64 { @@ -126,10 +128,16 @@ where } } -impl SeekableImplExt for T where ::Type: IsA {} +impl SeekableImplExt for T +where + ::Type: IsA, + ::Type: IsA, +{ +} unsafe impl IsImplementable for Seekable where + ::Type: IsA, ::Type: IsA, { fn interface_init(iface: &mut glib::Interface) { @@ -145,6 +153,7 @@ where unsafe extern "C" fn seekable_tell(seekable: *mut ffi::GSeekable) -> i64 where + ::Type: IsA, ::Type: IsA, { let instance = &*(seekable as *mut T::Instance); @@ -157,6 +166,7 @@ unsafe extern "C" fn seekable_can_seek( seekable: *mut ffi::GSeekable, ) -> glib::ffi::gboolean where + ::Type: IsA, ::Type: IsA, { let instance = &*(seekable as *mut T::Instance); @@ -173,6 +183,7 @@ unsafe extern "C" fn seekable_seek( err: *mut *mut glib::ffi::GError, ) -> glib::ffi::gboolean where + ::Type: IsA, ::Type: IsA, { let instance = &*(seekable as *mut T::Instance); @@ -199,6 +210,7 @@ unsafe extern "C" fn seekable_can_truncate( seekable: *mut ffi::GSeekable, ) -> glib::ffi::gboolean where + ::Type: IsA, ::Type: IsA, { let instance = &*(seekable as *mut T::Instance); @@ -214,6 +226,7 @@ unsafe extern "C" fn seekable_truncate( err: *mut *mut glib::ffi::GError, ) -> glib::ffi::gboolean where + ::Type: IsA, ::Type: IsA, { let instance = &*(seekable as *mut T::Instance); diff --git a/gio/src/subclass/socket_control_message.rs b/gio/src/subclass/socket_control_message.rs index 6eed7637fb7a..230604e08a47 100644 --- a/gio/src/subclass/socket_control_message.rs +++ b/gio/src/subclass/socket_control_message.rs @@ -6,6 +6,7 @@ use crate::{ffi, SocketControlMessage}; pub trait SocketControlMessageImpl: ObjectImpl where + ::Type: IsA, ::Type: IsA, { fn level(&self) -> i32 { @@ -31,6 +32,7 @@ where pub trait SocketControlMessageImplExt: ObjectSubclass + SocketControlMessageImpl where + ::Type: IsA, ::Type: IsA, { fn parent_level(&self) -> i32 { @@ -114,13 +116,16 @@ where } } -impl SocketControlMessageImplExt for T where - ::Type: IsA +impl SocketControlMessageImplExt for T +where + ::Type: IsA, + ::Type: IsA, { } unsafe impl IsSubclassable for SocketControlMessage where + ::Type: IsA, ::Type: IsA, { fn class_init(class: &mut ::glib::Class) { @@ -139,6 +144,7 @@ unsafe extern "C" fn socket_control_message_get_level i32 where + ::Type: IsA, ::Type: IsA, { let instance = &*(ptr as *mut T::Instance); @@ -151,6 +157,7 @@ unsafe extern "C" fn socket_control_message_get_type i32 where + ::Type: IsA, ::Type: IsA, { let instance = &*(ptr as *mut T::Instance); @@ -163,6 +170,7 @@ unsafe extern "C" fn socket_control_message_get_size usize where + ::Type: IsA, ::Type: IsA, { let instance = &*(ptr as *mut T::Instance); @@ -175,6 +183,7 @@ unsafe extern "C" fn socket_control_message_serialize::Type: IsA, ::Type: IsA, { let instance = &*(ptr as *mut T::Instance); @@ -192,6 +201,7 @@ unsafe extern "C" fn socket_control_message_deserialize *mut ffi::GSocketControlMessage where + ::Type: IsA, ::Type: IsA, { let data = std::slice::from_raw_parts(data as *mut u8, size); diff --git a/glib-macros/tests/object_subclass_dynamic.rs b/glib-macros/tests/object_subclass_dynamic.rs index 31ad917d215c..2b5a0bae9d8c 100644 --- a/glib-macros/tests/object_subclass_dynamic.rs +++ b/glib-macros/tests/object_subclass_dynamic.rs @@ -28,7 +28,12 @@ mod static_ { type Interface = MyStaticInterfaceClass; } - pub trait MyStaticInterfaceImpl: ObjectImpl + ObjectSubclass {} + pub trait MyStaticInterfaceImpl: ObjectImpl + ObjectSubclass + where + ::Type: IsA, + ::Type: IsA, + { + } // impl for an object subclass to register as a static type and that implements `MyStaticInterface`. #[derive(Default)] @@ -45,7 +50,12 @@ mod static_ { impl MyStaticInterfaceImpl for MyStaticType {} - pub trait MyStaticTypeImpl: ObjectImpl + ObjectSubclass {} + pub trait MyStaticTypeImpl: ObjectImpl + ObjectSubclass + where + ::Type: IsA, + ::Type: IsA, + { + } } // an object interface to register as a static type. @@ -53,14 +63,24 @@ mod static_ { pub struct MyStaticInterface(ObjectInterface); } - unsafe impl IsImplementable for MyStaticInterface {} + unsafe impl IsImplementable for MyStaticInterface + where + ::Type: IsA, + ::Type: IsA, + { + } // an object subclass to register as a static type and that implements `MyStaticInterface`. glib::wrapper! { pub struct MyStaticType(ObjectSubclass) @implements MyStaticInterface; } - unsafe impl IsSubclassable for MyStaticType {} + unsafe impl IsSubclassable for MyStaticType + where + ::Type: IsA, + ::Type: IsA, + { + } } use static_::{ @@ -95,7 +115,11 @@ mod module { type Interface = MyModuleInterfaceClass; } - pub trait MyModuleInterfaceImpl: ObjectImpl + ObjectSubclass {} + pub trait MyModuleInterfaceImpl: ObjectImpl + ObjectSubclass + where + ::Type: IsA, + { + } // impl for an object subclass to register as a dynamic type and that extends `MyStaticType` and that implements `MyStaticInterface` and `MyModuleInterface`. #[derive(Default)] @@ -139,7 +163,12 @@ mod module { type Interface = MyModuleInterfaceLazyClass; } - pub trait MyModuleInterfaceLazyImpl: ObjectImpl + ObjectSubclass {} + pub trait MyModuleInterfaceLazyImpl: ObjectImpl + ObjectSubclass + where + ::Type: IsA, + ::Type: IsA, + { + } // impl for an object subclass to lazy register as a dynamic type and that extends `MyStaticType` and that implements `MyStaticInterface` and `MyModuleInterfaceLazy`. #[derive(Default)] @@ -206,7 +235,12 @@ mod module { pub struct MyModuleInterface(ObjectInterface) @requires MyStaticInterface; } - unsafe impl IsImplementable for MyModuleInterface {} + unsafe impl IsImplementable for MyModuleInterface + where + ::Type: IsA, + ::Type: IsA, + { + } // an object subclass to register as a dynamic type and that extends `MyStaticType` and that implements `MyStaticInterface` and `MyModuleInterface`. glib::wrapper! { @@ -218,7 +252,12 @@ mod module { pub struct MyModuleInterfaceLazy(ObjectInterface) @requires MyStaticInterface; } - unsafe impl IsImplementable for MyModuleInterfaceLazy {} + unsafe impl IsImplementable for MyModuleInterfaceLazy + where + ::Type: IsA, + ::Type: IsA, + { + } // an object subclass to lazy register as a dynamic type and that extends `MyStaticType` that implements `MyStaticInterface` and `MyModuleInterfaceLazy`. glib::wrapper! { @@ -335,7 +374,12 @@ pub mod plugin { type Interface = MyPluginInterfaceClass; } - pub trait MyPluginInterfaceImpl: ObjectImpl + ObjectSubclass {} + pub trait MyPluginInterfaceImpl: ObjectImpl + ObjectSubclass + where + ::Type: IsA, + ::Type: IsA, + { + } // impl for an object subclass to register as a dynamic type and that extends `MyStaticType` and that implements `MyStaticInterface` and `MyPluginInterface`. #[derive(Default)] @@ -379,7 +423,12 @@ pub mod plugin { type Interface = MyPluginInterfaceLazyClass; } - pub trait MyPluginInterfaceLazyImpl: ObjectImpl + ObjectSubclass {} + pub trait MyPluginInterfaceLazyImpl: ObjectImpl + ObjectSubclass + where + ::Type: IsA, + ::Type: IsA, + { + } // impl for an object subclass to lazy register as a dynamic type and that extends `MyStaticType` and that implements `MyStaticInterface` and `MyPluginInterfaceLazy`. #[derive(Default)] @@ -400,7 +449,10 @@ pub mod plugin { impl MyStaticInterfaceImpl for MyPluginTypeLazy {} - impl MyPluginInterfaceLazyImpl for MyPluginTypeLazy {} + impl MyPluginInterfaceLazyImpl for MyPluginTypeLazy where + ::Type: IsA + { + } // impl for a type plugin (must implement `glib::TypePlugin`). #[derive(Default)] @@ -549,11 +601,16 @@ pub mod plugin { pub struct MyPluginInterface(ObjectInterface) @requires MyStaticInterface; } - unsafe impl IsImplementable for MyPluginInterface {} + unsafe impl IsImplementable for MyPluginInterface + where + ::Type: IsA, + ::Type: IsA, + { + } // an object subclass to register as a dynamic type and that extends `MyStaticType` and that implements `MyStaticInterface` and `MyPluginInterface`. glib::wrapper! { - pub struct MyPluginType(ObjectSubclass) @implements MyPluginInterface; + pub struct MyPluginType(ObjectSubclass) @extends MyStaticType, @implements MyPluginInterface, MyStaticInterface; } // an object interface to lazy register as a dynamic type and that extends `MyStaticInterface`. @@ -561,11 +618,16 @@ pub mod plugin { pub struct MyPluginInterfaceLazy(ObjectInterface) @requires MyStaticInterface; } - unsafe impl IsImplementable for MyPluginInterfaceLazy {} + unsafe impl IsImplementable for MyPluginInterfaceLazy + where + ::Type: IsA, + ::Type: IsA, + { + } // an object subclass to lazy register as a dynamic type and that extends `MyStaticType` that implements `MyStaticInterface` and `MyPluginInterfaceLazy`. glib::wrapper! { - pub struct MyPluginTypeLazy(ObjectSubclass) @implements MyPluginInterfaceLazy; + pub struct MyPluginTypeLazy(ObjectSubclass) @extends MyStaticType, @implements MyPluginInterfaceLazy, MyStaticInterface; } // a plugin (must implement `glib::TypePlugin`). diff --git a/glib-macros/tests/properties.rs b/glib-macros/tests/properties.rs index e4ca1da704bd..80d5fb43e913 100644 --- a/glib-macros/tests/properties.rs +++ b/glib-macros/tests/properties.rs @@ -42,7 +42,10 @@ mod base { pub struct Base(ObjectSubclass); } - unsafe impl IsSubclassable for Base {} + unsafe impl IsSubclassable for Base where + ::Type: IsA + { + } } #[cfg(test)] diff --git a/glib/src/gobject/dynamic_object.rs b/glib/src/gobject/dynamic_object.rs index 8736aa8ec580..36648b5af720 100644 --- a/glib/src/gobject/dynamic_object.rs +++ b/glib/src/gobject/dynamic_object.rs @@ -4,7 +4,7 @@ use crate::{ enums::{EnumValues, FlagsValues}, prelude::*, subclass::prelude::*, - InterfaceInfo, TypeFlags, TypeInfo, TypeModule, TypePlugin, + InterfaceInfo, Object, TypeFlags, TypeInfo, TypeModule, TypePlugin, }; mod sealed { @@ -44,6 +44,7 @@ pub trait DynamicObjectRegisterExt: AsRef + sealed::Sealed + 'static impl + ObjectSubclassIsExt> DynamicObjectRegisterExt for O where O::Subclass: TypePluginRegisterImpl, + ::Type: IsA, ::Type: IsA, { fn add_dynamic_interface( diff --git a/glib/src/subclass/object.rs b/glib/src/subclass/object.rs index fc4b42b6cff7..95f2cbf5f258 100644 --- a/glib/src/subclass/object.rs +++ b/glib/src/subclass/object.rs @@ -19,7 +19,10 @@ use crate::{ /// /// This allows overriding the virtual methods of `glib::Object`. Except for /// `finalize` as implementing `Drop` would allow the same behavior. -pub trait ObjectImpl: ObjectSubclass { +pub trait ObjectImpl: ObjectSubclass +where + ::Type: IsA, +{ // rustdoc-stripper-ignore-next /// Properties installed for this type. fn properties() -> &'static [ParamSpec] { @@ -92,7 +95,9 @@ unsafe extern "C" fn property( id: u32, value: *mut gobject_ffi::GValue, pspec: *mut gobject_ffi::GParamSpec, -) { +) where + ::Type: IsA, +{ let instance = &*(obj as *mut T::Instance); let imp = instance.imp(); @@ -116,7 +121,9 @@ unsafe extern "C" fn set_property( id: u32, value: *mut gobject_ffi::GValue, pspec: *mut gobject_ffi::GParamSpec, -) { +) where + ::Type: IsA, +{ let instance = &*(obj as *mut T::Instance); let imp = instance.imp(); imp.set_property( @@ -126,7 +133,10 @@ unsafe extern "C" fn set_property( ); } -unsafe extern "C" fn constructed(obj: *mut gobject_ffi::GObject) { +unsafe extern "C" fn constructed(obj: *mut gobject_ffi::GObject) +where + ::Type: IsA, +{ let instance = &*(obj as *mut T::Instance); let imp = instance.imp(); @@ -136,7 +146,9 @@ unsafe extern "C" fn constructed(obj: *mut gobject_ffi::GObject) unsafe extern "C" fn notify( obj: *mut gobject_ffi::GObject, pspec: *mut gobject_ffi::GParamSpec, -) { +) where + ::Type: IsA, +{ let instance = &*(obj as *mut T::Instance); let imp = instance.imp(); imp.notify(&from_glib_borrow(pspec)); @@ -146,13 +158,18 @@ unsafe extern "C" fn dispatch_properties_changed( obj: *mut gobject_ffi::GObject, n_pspecs: u32, pspecs: *mut *mut gobject_ffi::GParamSpec, -) { +) where + ::Type: IsA, +{ let instance = &*(obj as *mut T::Instance); let imp = instance.imp(); imp.dispatch_properties_changed(Slice::from_glib_borrow_num(pspecs, n_pspecs as _)); } -unsafe extern "C" fn dispose(obj: *mut gobject_ffi::GObject) { +unsafe extern "C" fn dispose(obj: *mut gobject_ffi::GObject) +where + ::Type: IsA, +{ let instance = &*(obj as *mut T::Instance); let imp = instance.imp(); @@ -213,7 +230,10 @@ pub unsafe trait ObjectClassSubclassExt: Sized + 'static { unsafe impl ObjectClassSubclassExt for crate::Class {} -unsafe impl IsSubclassable for Object { +unsafe impl IsSubclassable for Object +where + ::Type: IsA, +{ fn class_init(class: &mut crate::Class) { let klass = class.as_mut(); klass.set_property = Some(set_property::); @@ -253,7 +273,10 @@ unsafe impl IsSubclassable for Object { fn instance_init(_instance: &mut super::InitializingObject) {} } -pub trait ObjectImplExt: ObjectSubclass + ObjectImpl { +pub trait ObjectImplExt: ObjectSubclass + ObjectImpl +where + ::Type: IsA, +{ // rustdoc-stripper-ignore-next /// Chain up to the parent class' implementation of `glib::Object::constructed()`. #[inline] @@ -316,7 +339,7 @@ pub trait ObjectImplExt: ObjectSubclass + ObjectImpl { } } -impl ObjectImplExt for T {} +impl ObjectImplExt for T where ::Type: IsA {} #[cfg(test)] mod test { diff --git a/glib/src/subclass/type_module.rs b/glib/src/subclass/type_module.rs index cd78adade1ab..7382957df4ab 100644 --- a/glib/src/subclass/type_module.rs +++ b/glib/src/subclass/type_module.rs @@ -1,9 +1,10 @@ // Take a look at the license at the top of the repository in the LICENSE file. -use crate::{ffi, gobject_ffi, prelude::*, subclass::prelude::*, translate::*, TypeModule}; +use crate::{ffi, gobject_ffi, prelude::*, subclass::prelude::*, translate::*, Object, TypeModule}; pub trait TypeModuleImpl: ObjectImpl where + ::Type: IsA, ::Type: IsA, { // rustdoc-stripper-ignore-next @@ -26,6 +27,7 @@ where pub trait TypeModuleImplExt: ObjectSubclass + TypeModuleImpl where + ::Type: IsA, ::Type: IsA, { fn parent_load(&self) -> bool; @@ -34,6 +36,7 @@ where impl TypeModuleImplExt for T where + ::Type: IsA, ::Type: IsA, { fn parent_load(&self) -> bool { @@ -69,6 +72,7 @@ where unsafe impl IsSubclassable for TypeModule where + ::Type: IsA, ::Type: IsA, { fn class_init(class: &mut crate::Class) { @@ -84,6 +88,7 @@ unsafe extern "C" fn load( type_module: *mut gobject_ffi::GTypeModule, ) -> ffi::gboolean where + ::Type: IsA, ::Type: IsA, { let instance = &*(type_module as *mut T::Instance); @@ -107,6 +112,7 @@ where unsafe extern "C" fn unload(type_module: *mut gobject_ffi::GTypeModule) where + ::Type: IsA, ::Type: IsA, { let instance = &*(type_module as *mut T::Instance); diff --git a/glib/src/subclass/type_plugin.rs b/glib/src/subclass/type_plugin.rs index 9e8ab6908b0a..04fd1bb4035d 100644 --- a/glib/src/subclass/type_plugin.rs +++ b/glib/src/subclass/type_plugin.rs @@ -3,11 +3,12 @@ use crate::enums::{EnumValues, FlagsValues}; use crate::{ ffi, gobject_ffi, prelude::*, subclass::prelude::*, translate::*, Interface, InterfaceInfo, - Type, TypeFlags, TypeInfo, TypePlugin, TypeValueTable, + Object, Type, TypeFlags, TypeInfo, TypePlugin, TypeValueTable, }; pub trait TypePluginImpl: ObjectImpl where + ::Type: IsA, ::Type: IsA, { fn use_plugin(&self) { @@ -29,6 +30,7 @@ where pub trait TypePluginImplExt: ObjectSubclass + TypePluginImpl where + ::Type: IsA, ::Type: IsA, { fn parent_use_plugin(&self); @@ -43,6 +45,7 @@ where impl TypePluginImplExt for T where + ::Type: IsA, ::Type: IsA, { fn parent_use_plugin(&self) { @@ -124,6 +127,7 @@ where unsafe impl IsImplementable for TypePlugin where + ::Type: IsA, ::Type: IsA, { fn interface_init(iface: &mut Interface) { @@ -138,6 +142,7 @@ where unsafe extern "C" fn use_plugin(type_plugin: *mut gobject_ffi::GTypePlugin) where + ::Type: IsA, ::Type: IsA, { let instance = &*(type_plugin as *mut T::Instance); @@ -148,6 +153,7 @@ where unsafe extern "C" fn unuse_plugin(type_plugin: *mut gobject_ffi::GTypePlugin) where + ::Type: IsA, ::Type: IsA, { let instance = &*(type_plugin as *mut T::Instance); @@ -162,6 +168,7 @@ unsafe extern "C" fn complete_type_info( info_ptr: *mut gobject_ffi::GTypeInfo, value_table_ptr: *mut gobject_ffi::GTypeValueTable, ) where + ::Type: IsA, ::Type: IsA, { assert!(!info_ptr.is_null()); @@ -184,6 +191,7 @@ unsafe extern "C" fn complete_interface_info( interface_gtype: ffi::GType, info_ptr: *mut gobject_ffi::GInterfaceInfo, ) where + ::Type: IsA, ::Type: IsA, { assert!(!info_ptr.is_null()); @@ -199,6 +207,7 @@ unsafe extern "C" fn complete_interface_info( pub trait TypePluginRegisterImpl: ObjectImpl + TypePluginImpl where + ::Type: IsA, ::Type: IsA, { fn add_dynamic_interface( diff --git a/glib/tests/subclass_compiletest/04-auto-send-sync-with-send-sync-parent.rs b/glib/tests/subclass_compiletest/04-auto-send-sync-with-send-sync-parent.rs index f3c38aebfe51..22e63f5e4298 100644 --- a/glib/tests/subclass_compiletest/04-auto-send-sync-with-send-sync-parent.rs +++ b/glib/tests/subclass_compiletest/04-auto-send-sync-with-send-sync-parent.rs @@ -19,9 +19,16 @@ glib::wrapper! { pub struct TestParent(ObjectSubclass); } -pub trait TestParentImpl: glib::subclass::prelude::ObjectImpl + Send + Sync {} +pub trait TestParentImpl: glib::subclass::prelude::ObjectImpl + Send + Sync +where + ::Type: glib::prelude::IsA, +{ +} -unsafe impl glib::subclass::prelude::IsSubclassable for TestParent {} +unsafe impl glib::subclass::prelude::IsSubclassable for TestParent where + ::Type: glib::prelude::IsA +{ +} impl Default for TestParent { fn default() -> Self { diff --git a/glib/tests/subclass_compiletest/05-no-auto-send-sync-with-non-send-sync-parent.rs b/glib/tests/subclass_compiletest/05-no-auto-send-sync-with-non-send-sync-parent.rs index 836f225b82d1..72114287d8cb 100644 --- a/glib/tests/subclass_compiletest/05-no-auto-send-sync-with-non-send-sync-parent.rs +++ b/glib/tests/subclass_compiletest/05-no-auto-send-sync-with-non-send-sync-parent.rs @@ -20,9 +20,16 @@ glib::wrapper! { pub struct TestParent(ObjectSubclass); } -pub trait TestParentImpl: glib::subclass::prelude::ObjectImpl {} +pub trait TestParentImpl: glib::subclass::prelude::ObjectImpl +where + ::Type: glib::prelude::IsA, +{ +} -unsafe impl glib::subclass::prelude::IsSubclassable for TestParent {} +unsafe impl glib::subclass::prelude::IsSubclassable for TestParent where + ::Type: glib::prelude::IsA +{ +} impl Default for TestParent { fn default() -> Self { diff --git a/glib/tests/subclass_compiletest/05-no-auto-send-sync-with-non-send-sync-parent.stderr b/glib/tests/subclass_compiletest/05-no-auto-send-sync-with-non-send-sync-parent.stderr index 7a127ed6462b..b51e1bfed782 100644 --- a/glib/tests/subclass_compiletest/05-no-auto-send-sync-with-non-send-sync-parent.stderr +++ b/glib/tests/subclass_compiletest/05-no-auto-send-sync-with-non-send-sync-parent.stderr @@ -1,7 +1,7 @@ error[E0277]: `RefCell` cannot be shared between threads safely - --> tests/subclass_compiletest/05-no-auto-send-sync-with-non-send-sync-parent.rs:66:11 + --> tests/subclass_compiletest/05-no-auto-send-sync-with-non-send-sync-parent.rs:73:11 | -66 | check(&obj); +73 | check(&obj); | ----- ^^^^ `RefCell` cannot be shared between threads safely | | | required by a bound introduced by this call @@ -21,12 +21,12 @@ note: required because it appears within the type `TestParent` | ^^^^^^^^^^ = note: required for `TypedObjectRef` to implement `Send` note: required because it appears within the type `TestObject` - --> tests/subclass_compiletest/05-no-auto-send-sync-with-non-send-sync-parent.rs:53:16 + --> tests/subclass_compiletest/05-no-auto-send-sync-with-non-send-sync-parent.rs:60:16 | -53 | pub struct TestObject(ObjectSubclass) @extends TestParent; +60 | pub struct TestObject(ObjectSubclass) @extends TestParent; | ^^^^^^^^^^ note: required by a bound in `main::check` - --> tests/subclass_compiletest/05-no-auto-send-sync-with-non-send-sync-parent.rs:63:17 + --> tests/subclass_compiletest/05-no-auto-send-sync-with-non-send-sync-parent.rs:70:17 | -63 | fn check(_obj: &T) {} +70 | fn check(_obj: &T) {} | ^^^^ required by this bound in `check` diff --git a/glib/tests/subclass_compiletest/06-no-auto-send-sync-with-non-send-sync-ffi-parent.rs b/glib/tests/subclass_compiletest/06-no-auto-send-sync-with-non-send-sync-ffi-parent.rs index e8e9338efa61..566b8c834907 100644 --- a/glib/tests/subclass_compiletest/06-no-auto-send-sync-with-non-send-sync-ffi-parent.rs +++ b/glib/tests/subclass_compiletest/06-no-auto-send-sync-with-non-send-sync-ffi-parent.rs @@ -7,10 +7,14 @@ glib::wrapper! { } } -pub trait InitiallyUnownedImpl: glib::subclass::prelude::ObjectImpl {} +pub trait InitiallyUnownedImpl: glib::subclass::prelude::ObjectImpl +where + ::Type: glib::prelude::IsA, +{ +} -unsafe impl glib::subclass::prelude::IsSubclassable - for InitiallyUnowned +unsafe impl glib::subclass::prelude::IsSubclassable for InitiallyUnowned where + ::Type: glib::prelude::IsA { } diff --git a/glib/tests/subclass_compiletest/06-no-auto-send-sync-with-non-send-sync-ffi-parent.stderr b/glib/tests/subclass_compiletest/06-no-auto-send-sync-with-non-send-sync-ffi-parent.stderr index 7a61c3da10c8..78e094d48c35 100644 --- a/glib/tests/subclass_compiletest/06-no-auto-send-sync-with-non-send-sync-ffi-parent.stderr +++ b/glib/tests/subclass_compiletest/06-no-auto-send-sync-with-non-send-sync-ffi-parent.stderr @@ -1,7 +1,7 @@ error[E0277]: `*mut c_void` cannot be sent between threads safely - --> tests/subclass_compiletest/06-no-auto-send-sync-with-non-send-sync-ffi-parent.rs:50:11 + --> tests/subclass_compiletest/06-no-auto-send-sync-with-non-send-sync-ffi-parent.rs:54:11 | -50 | check(&obj); +54 | check(&obj); | ----- ^^^^ `*mut c_void` cannot be sent between threads safely | | | required by a bound introduced by this call @@ -15,20 +15,20 @@ note: required because it appears within the type `InitiallyUnowned` | ^^^^^^^^^^^^^^^^ = note: required for `TypedObjectRef` to implement `Send` note: required because it appears within the type `TestObject` - --> tests/subclass_compiletest/06-no-auto-send-sync-with-non-send-sync-ffi-parent.rs:37:16 + --> tests/subclass_compiletest/06-no-auto-send-sync-with-non-send-sync-ffi-parent.rs:41:16 | -37 | pub struct TestObject(ObjectSubclass) @extends InitiallyUnowned; +41 | pub struct TestObject(ObjectSubclass) @extends InitiallyUnowned; | ^^^^^^^^^^ note: required by a bound in `main::check` - --> tests/subclass_compiletest/06-no-auto-send-sync-with-non-send-sync-ffi-parent.rs:47:17 + --> tests/subclass_compiletest/06-no-auto-send-sync-with-non-send-sync-ffi-parent.rs:51:17 | -47 | fn check(_obj: &T) {} +51 | fn check(_obj: &T) {} | ^^^^ required by this bound in `check` error[E0277]: `*mut c_void` cannot be shared between threads safely - --> tests/subclass_compiletest/06-no-auto-send-sync-with-non-send-sync-ffi-parent.rs:50:11 + --> tests/subclass_compiletest/06-no-auto-send-sync-with-non-send-sync-ffi-parent.rs:54:11 | -50 | check(&obj); +54 | check(&obj); | ----- ^^^^ `*mut c_void` cannot be shared between threads safely | | | required by a bound introduced by this call @@ -42,12 +42,12 @@ note: required because it appears within the type `InitiallyUnowned` | ^^^^^^^^^^^^^^^^ = note: required for `TypedObjectRef` to implement `Send` note: required because it appears within the type `TestObject` - --> tests/subclass_compiletest/06-no-auto-send-sync-with-non-send-sync-ffi-parent.rs:37:16 + --> tests/subclass_compiletest/06-no-auto-send-sync-with-non-send-sync-ffi-parent.rs:41:16 | -37 | pub struct TestObject(ObjectSubclass) @extends InitiallyUnowned; +41 | pub struct TestObject(ObjectSubclass) @extends InitiallyUnowned; | ^^^^^^^^^^ note: required by a bound in `main::check` - --> tests/subclass_compiletest/06-no-auto-send-sync-with-non-send-sync-ffi-parent.rs:47:17 + --> tests/subclass_compiletest/06-no-auto-send-sync-with-non-send-sync-ffi-parent.rs:51:17 | -47 | fn check(_obj: &T) {} +51 | fn check(_obj: &T) {} | ^^^^ required by this bound in `check` From 80569bd361d2308aa660b24e578443734607581f Mon Sep 17 00:00:00 2001 From: Fina Wilke Date: Thu, 3 Oct 2024 16:37:50 +0200 Subject: [PATCH 3/3] changelog: Fix typo --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 00ff0f4cf8c6..97ab388a08ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -258,7 +258,7 @@ Paolo Borelli: - gio: use `StrV` for the `file_info` API - gio: use `GStr` for the manual extension point implementation - glib: list: mark as transparent and impl TransparentPtr -- glib: Rename `StrVItem` to `GStrPtr` and make it clonable and transparent +- glib: Rename `StrVItem` to `GStrPtr` and make it cloneable and transparent - glib: `key_file`: return `PtrSlice` - glib-macros: further tweak docs - glib: Rename `GStrPtr` to `GStringPtr`