diff --git a/gdk-pixbuf/src/subclass/pixbuf_animation.rs b/gdk-pixbuf/src/subclass/pixbuf_animation.rs index d51da8c3866b..ee5ff297496d 100644 --- a/gdk-pixbuf/src/subclass/pixbuf_animation.rs +++ b/gdk-pixbuf/src/subclass/pixbuf_animation.rs @@ -34,16 +34,7 @@ where } } -mod sealed { - use glib::{prelude::*, subclass::prelude::*}; - pub trait Sealed {} - impl Sealed for T where - ::Type: IsA - { - } -} - -pub trait PixbufAnimationImplExt: sealed::Sealed + ObjectSubclass +pub trait PixbufAnimationImplExt: ObjectSubclass + PixbufAnimationImpl where ::Type: IsA, { diff --git a/gdk-pixbuf/src/subclass/pixbuf_animation_iter.rs b/gdk-pixbuf/src/subclass/pixbuf_animation_iter.rs index 4b97b5098e6d..03e16a1db22c 100644 --- a/gdk-pixbuf/src/subclass/pixbuf_animation_iter.rs +++ b/gdk-pixbuf/src/subclass/pixbuf_animation_iter.rs @@ -35,16 +35,7 @@ where } } -mod sealed { - use glib::{prelude::*, subclass::prelude::*}; - pub trait Sealed {} - impl Sealed for T where - ::Type: IsA - { - } -} - -pub trait PixbufAnimationIterImplExt: sealed::Sealed + ObjectSubclass +pub trait PixbufAnimationIterImplExt: ObjectSubclass + PixbufAnimationIterImpl where ::Type: IsA, { diff --git a/gdk-pixbuf/src/subclass/pixbuf_loader.rs b/gdk-pixbuf/src/subclass/pixbuf_loader.rs index 01d152cb33f8..e99388644043 100644 --- a/gdk-pixbuf/src/subclass/pixbuf_loader.rs +++ b/gdk-pixbuf/src/subclass/pixbuf_loader.rs @@ -28,16 +28,7 @@ where } } -mod sealed { - use glib::{prelude::*, subclass::prelude::*}; - pub trait Sealed {} - impl Sealed for T where - ::Type: IsA - { - } -} - -pub trait PixbufLoaderImplExt: sealed::Sealed + ObjectSubclass +pub trait PixbufLoaderImplExt: ObjectSubclass + PixbufLoaderImpl where ::Type: IsA, { 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/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 c93a22cbb167..cd78adade1ab 100644 --- a/glib/src/subclass/type_module.rs +++ b/glib/src/subclass/type_module.rs @@ -2,7 +2,7 @@ use crate::{ffi, gobject_ffi, prelude::*, subclass::prelude::*, translate::*, TypeModule}; -pub trait TypeModuleImpl: ObjectImpl + TypeModuleImplExt +pub trait TypeModuleImpl: ObjectImpl where ::Type: IsA, { @@ -24,7 +24,7 @@ where fn unload(&self); } -pub trait TypeModuleImplExt: ObjectSubclass +pub trait TypeModuleImplExt: ObjectSubclass + TypeModuleImpl where ::Type: IsA, { diff --git a/glib/src/subclass/type_plugin.rs b/glib/src/subclass/type_plugin.rs index 9700225d01b0..9e8ab6908b0a 100644 --- a/glib/src/subclass/type_plugin.rs +++ b/glib/src/subclass/type_plugin.rs @@ -6,7 +6,7 @@ use crate::{ Type, TypeFlags, TypeInfo, TypePlugin, TypeValueTable, }; -pub trait TypePluginImpl: ObjectImpl + TypePluginImplExt +pub trait TypePluginImpl: ObjectImpl where ::Type: IsA, { @@ -27,7 +27,7 @@ where } } -pub trait TypePluginImplExt: ObjectSubclass +pub trait TypePluginImplExt: ObjectSubclass + TypePluginImpl where ::Type: IsA, {