Skip to content

Commit

Permalink
gio: Add additional type bounds to Impl traits
Browse files Browse the repository at this point in the history
Remove the Sealed traits, as they are now unnecessary.
  • Loading branch information
felinira committed Sep 29, 2024
1 parent 0cbea41 commit 03bdfd2
Show file tree
Hide file tree
Showing 17 changed files with 351 additions and 194 deletions.
11 changes: 1 addition & 10 deletions gdk-pixbuf/src/subclass/pixbuf_animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,7 @@ where
}
}

mod sealed {
use glib::{prelude::*, subclass::prelude::*};
pub trait Sealed {}
impl<T: super::PixbufAnimationImplExt> Sealed for T where
<T as ObjectSubclass>::Type: IsA<super::PixbufAnimation>
{
}
}

pub trait PixbufAnimationImplExt: sealed::Sealed + ObjectSubclass
pub trait PixbufAnimationImplExt: ObjectSubclass + PixbufAnimationImpl
where
<Self as ObjectSubclass>::Type: IsA<PixbufAnimation>,
{
Expand Down
11 changes: 1 addition & 10 deletions gdk-pixbuf/src/subclass/pixbuf_animation_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,7 @@ where
}
}

mod sealed {
use glib::{prelude::*, subclass::prelude::*};
pub trait Sealed {}
impl<T: super::PixbufAnimationIterImplExt> Sealed for T where
<T as ObjectSubclass>::Type: IsA<super::PixbufAnimationIter>
{
}
}

pub trait PixbufAnimationIterImplExt: sealed::Sealed + ObjectSubclass
pub trait PixbufAnimationIterImplExt: ObjectSubclass + PixbufAnimationIterImpl
where
<Self as ObjectSubclass>::Type: IsA<PixbufAnimationIter>,
{
Expand Down
11 changes: 1 addition & 10 deletions gdk-pixbuf/src/subclass/pixbuf_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,7 @@ where
}
}

mod sealed {
use glib::{prelude::*, subclass::prelude::*};
pub trait Sealed {}
impl<T: super::PixbufLoaderImplExt> Sealed for T where
<Self as ObjectSubclass>::Type: IsA<super::PixbufLoader>
{
}
}

pub trait PixbufLoaderImplExt: sealed::Sealed + ObjectSubclass
pub trait PixbufLoaderImplExt: ObjectSubclass + PixbufLoaderImpl
where
<Self as ObjectSubclass>::Type: IsA<PixbufLoader>,
{
Expand Down
87 changes: 64 additions & 23 deletions gio/src/subclass/action_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
<Self as ObjectSubclass>::Type: IsA<ActionGroup>,
{
fn action_added(&self, action_name: &str) {
self.parent_action_added(action_name);
}
Expand Down Expand Up @@ -73,12 +76,10 @@ pub trait ActionGroupImpl: ObjectImpl {
)>;
}

mod sealed {
pub trait Sealed {}
impl<T: super::ActionGroupImplExt> Sealed for T {}
}

pub trait ActionGroupImplExt: sealed::Sealed + ObjectSubclass {
pub trait ActionGroupImplExt: ObjectSubclass + ActionGroupImpl
where
<Self as ObjectSubclass>::Type: IsA<ActionGroup>,
{
fn parent_action_added(&self, action_name: &str) {
unsafe {
let type_data = Self::type_data();
Expand Down Expand Up @@ -341,9 +342,13 @@ pub trait ActionGroupImplExt: sealed::Sealed + ObjectSubclass {
}
}

impl<T: ActionGroupImpl> ActionGroupImplExt for T {}
impl<T: ActionGroupImpl> ActionGroupImplExt for T where <T as ObjectSubclass>::Type: IsA<ActionGroup>
{}

unsafe impl<T: ActionGroupImpl> IsImplementable<T> for ActionGroup {
unsafe impl<T: ActionGroupImpl> IsImplementable<T> for ActionGroup
where
<T as ObjectSubclass>::Type: IsA<ActionGroup>,
{
fn interface_init(iface: &mut glib::Interface<Self>) {
let iface = iface.as_mut();

Expand All @@ -367,7 +372,10 @@ unsafe impl<T: ActionGroupImpl> IsImplementable<T> for ActionGroup {
unsafe extern "C" fn action_group_has_action<T: ActionGroupImpl>(
action_group: *mut ffi::GActionGroup,
action_nameptr: *const libc::c_char,
) -> glib::ffi::gboolean {
) -> glib::ffi::gboolean
where
<T as ObjectSubclass>::Type: IsA<ActionGroup>,
{
let instance = &*(action_group as *mut T::Instance);
let action_name = GString::from_glib_borrow(action_nameptr);
let imp = instance.imp();
Expand All @@ -378,7 +386,10 @@ unsafe extern "C" fn action_group_has_action<T: ActionGroupImpl>(
unsafe extern "C" fn action_group_get_action_enabled<T: ActionGroupImpl>(
action_group: *mut ffi::GActionGroup,
action_nameptr: *const libc::c_char,
) -> glib::ffi::gboolean {
) -> glib::ffi::gboolean
where
<T as ObjectSubclass>::Type: IsA<ActionGroup>,
{
let instance = &*(action_group as *mut T::Instance);
let imp = instance.imp();
let action_name = GString::from_glib_borrow(action_nameptr);
Expand All @@ -399,7 +410,10 @@ impl<T, F: Fn(*mut T) + 'static> Drop for PtrHolder<T, F> {
unsafe extern "C" fn action_group_get_action_parameter_type<T: ActionGroupImpl>(
action_group: *mut ffi::GActionGroup,
action_nameptr: *const libc::c_char,
) -> *const glib::ffi::GVariantType {
) -> *const glib::ffi::GVariantType
where
<T as ObjectSubclass>::Type: IsA<ActionGroup>,
{
let instance = &*(action_group as *mut T::Instance);
let imp = instance.imp();
let action_name = GString::from_glib_borrow(action_nameptr);
Expand Down Expand Up @@ -428,7 +442,10 @@ unsafe extern "C" fn action_group_get_action_parameter_type<T: ActionGroupImpl>(
unsafe extern "C" fn action_group_get_action_state_type<T: ActionGroupImpl>(
action_group: *mut ffi::GActionGroup,
action_nameptr: *const libc::c_char,
) -> *const glib::ffi::GVariantType {
) -> *const glib::ffi::GVariantType
where
<T as ObjectSubclass>::Type: IsA<ActionGroup>,
{
let instance = &*(action_group as *mut T::Instance);
let imp = instance.imp();
let action_name = GString::from_glib_borrow(action_nameptr);
Expand Down Expand Up @@ -457,7 +474,10 @@ unsafe extern "C" fn action_group_get_action_state_type<T: ActionGroupImpl>(
unsafe extern "C" fn action_group_get_action_state_hint<T: ActionGroupImpl>(
action_group: *mut ffi::GActionGroup,
action_nameptr: *const libc::c_char,
) -> *mut glib::ffi::GVariant {
) -> *mut glib::ffi::GVariant
where
<T as ObjectSubclass>::Type: IsA<ActionGroup>,
{
let instance = &*(action_group as *mut T::Instance);
let imp = instance.imp();
let action_name = GString::from_glib_borrow(action_nameptr);
Expand Down Expand Up @@ -485,7 +505,10 @@ unsafe extern "C" fn action_group_get_action_state_hint<T: ActionGroupImpl>(
unsafe extern "C" fn action_group_get_action_state<T: ActionGroupImpl>(
action_group: *mut ffi::GActionGroup,
action_nameptr: *const libc::c_char,
) -> *mut glib::ffi::GVariant {
) -> *mut glib::ffi::GVariant
where
<T as ObjectSubclass>::Type: IsA<ActionGroup>,
{
let instance = &*(action_group as *mut T::Instance);
let imp = instance.imp();
let action_name = GString::from_glib_borrow(action_nameptr);
Expand All @@ -512,7 +535,9 @@ unsafe extern "C" fn action_group_change_action_state<T: ActionGroupImpl>(
action_group: *mut ffi::GActionGroup,
action_nameptr: *const libc::c_char,
stateptr: *mut glib::ffi::GVariant,
) {
) where
<T as ObjectSubclass>::Type: IsA<ActionGroup>,
{
let instance = &*(action_group as *mut T::Instance);
let imp = instance.imp();
let action_name = GString::from_glib_borrow(action_nameptr);
Expand All @@ -525,7 +550,9 @@ unsafe extern "C" fn action_group_activate_action<T: ActionGroupImpl>(
action_group: *mut ffi::GActionGroup,
action_nameptr: *const libc::c_char,
parameterptr: *mut glib::ffi::GVariant,
) {
) where
<T as ObjectSubclass>::Type: IsA<ActionGroup>,
{
let instance = &*(action_group as *mut T::Instance);
let imp = instance.imp();
let action_name = GString::from_glib_borrow(action_nameptr);
Expand All @@ -537,7 +564,9 @@ unsafe extern "C" fn action_group_activate_action<T: ActionGroupImpl>(
unsafe extern "C" fn action_group_action_added<T: ActionGroupImpl>(
action_group: *mut ffi::GActionGroup,
action_nameptr: *const libc::c_char,
) {
) where
<T as ObjectSubclass>::Type: IsA<ActionGroup>,
{
let instance = &*(action_group as *mut T::Instance);
let imp = instance.imp();
let action_name = GString::from_glib_borrow(action_nameptr);
Expand All @@ -548,7 +577,9 @@ unsafe extern "C" fn action_group_action_added<T: ActionGroupImpl>(
unsafe extern "C" fn action_group_action_removed<T: ActionGroupImpl>(
action_group: *mut ffi::GActionGroup,
action_nameptr: *const libc::c_char,
) {
) where
<T as ObjectSubclass>::Type: IsA<ActionGroup>,
{
let instance = &*(action_group as *mut T::Instance);
let imp = instance.imp();
let action_name = GString::from_glib_borrow(action_nameptr);
Expand All @@ -560,7 +591,9 @@ unsafe extern "C" fn action_group_action_enabled_changed<T: ActionGroupImpl>(
action_group: *mut ffi::GActionGroup,
action_nameptr: *const libc::c_char,
enabled: glib::ffi::gboolean,
) {
) where
<T as ObjectSubclass>::Type: IsA<ActionGroup>,
{
let instance = &*(action_group as *mut T::Instance);
let imp = instance.imp();
let action_name = GString::from_glib_borrow(action_nameptr);
Expand All @@ -572,7 +605,9 @@ unsafe extern "C" fn action_group_action_state_changed<T: ActionGroupImpl>(
action_group: *mut ffi::GActionGroup,
action_nameptr: *const libc::c_char,
stateptr: *mut glib::ffi::GVariant,
) {
) where
<T as ObjectSubclass>::Type: IsA<ActionGroup>,
{
let instance = &*(action_group as *mut T::Instance);
let imp = instance.imp();
let action_name = GString::from_glib_borrow(action_nameptr);
Expand All @@ -583,7 +618,10 @@ unsafe extern "C" fn action_group_action_state_changed<T: ActionGroupImpl>(

unsafe extern "C" fn action_group_list_actions<T: ActionGroupImpl>(
action_group: *mut ffi::GActionGroup,
) -> *mut *mut libc::c_char {
) -> *mut *mut libc::c_char
where
<T as ObjectSubclass>::Type: IsA<ActionGroup>,
{
let instance = &*(action_group as *mut T::Instance);
let imp = instance.imp();

Expand All @@ -609,7 +647,10 @@ unsafe extern "C" fn action_group_query_action<T: ActionGroupImpl>(
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
<T as ObjectSubclass>::Type: IsA<ActionGroup>,
{
let instance = &*(action_group as *mut T::Instance);
let imp = instance.imp();
let action_name = GString::from_glib_borrow(action_nameptr);
Expand Down
32 changes: 20 additions & 12 deletions gio/src/subclass/action_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
<Self as ObjectSubclass>::Type: IsA<ActionMap>,
{
fn lookup_action(&self, action_name: &str) -> Option<Action>;
fn add_action(&self, action: &Action);
fn remove_action(&self, action_name: &str);
}

mod sealed {
pub trait Sealed {}
impl<T: super::ActionMapImplExt> Sealed for T {}
}

pub trait ActionMapImplExt: sealed::Sealed + ObjectSubclass {
pub trait ActionMapImplExt: ObjectSubclass + ActionMapImpl
where
<Self as ObjectSubclass>::Type: IsA<ActionMap>,
{
fn parent_lookup_action(&self, name: &str) -> Option<Action> {
unsafe {
let type_data = Self::type_data();
Expand Down Expand Up @@ -68,11 +69,11 @@ pub trait ActionMapImplExt: sealed::Sealed + ObjectSubclass {
}
}

impl<T: ActionMapImpl> ActionMapImplExt for T {}
impl<T: ActionMapImpl> ActionMapImplExt for T where <T as ObjectSubclass>::Type: IsA<ActionMap> {}

unsafe impl<T: ActionMapImpl> IsImplementable<T> for ActionMap
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<ActionMap>,
{
fn interface_init(iface: &mut glib::Interface<Self>) {
let iface = iface.as_mut();
Expand All @@ -86,7 +87,10 @@ where
unsafe extern "C" fn action_map_lookup_action<T: ActionMapImpl>(
action_map: *mut ffi::GActionMap,
action_nameptr: *const libc::c_char,
) -> *mut ffi::GAction {
) -> *mut ffi::GAction
where
<T as ObjectSubclass>::Type: IsA<ActionMap>,
{
let instance = &*(action_map as *mut T::Instance);
let action_name = GString::from_glib_borrow(action_nameptr);
let imp = instance.imp();
Expand Down Expand Up @@ -116,7 +120,9 @@ unsafe extern "C" fn action_map_lookup_action<T: ActionMapImpl>(
unsafe extern "C" fn action_map_add_action<T: ActionMapImpl>(
action_map: *mut ffi::GActionMap,
actionptr: *mut ffi::GAction,
) {
) where
<T as ObjectSubclass>::Type: IsA<ActionMap>,
{
let instance = &*(action_map as *mut T::Instance);
let imp = instance.imp();
let action: Borrowed<Action> = from_glib_borrow(actionptr);
Expand All @@ -127,7 +133,9 @@ unsafe extern "C" fn action_map_add_action<T: ActionMapImpl>(
unsafe extern "C" fn action_map_remove_action<T: ActionMapImpl>(
action_map: *mut ffi::GActionMap,
action_nameptr: *const libc::c_char,
) {
) where
<T as ObjectSubclass>::Type: IsA<ActionMap>,
{
let instance = &*(action_map as *mut T::Instance);
let imp = instance.imp();
let action_name = GString::from_glib_borrow(action_nameptr);
Expand Down
Loading

0 comments on commit 03bdfd2

Please sign in to comment.