Skip to content

Commit

Permalink
Add additional type bounds to Impl traits
Browse files Browse the repository at this point in the history
  • Loading branch information
felinira committed Oct 3, 2024
1 parent 739e2fa commit d50724f
Show file tree
Hide file tree
Showing 66 changed files with 1,046 additions and 134 deletions.
14 changes: 13 additions & 1 deletion examples/virtual_methods/base_button/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ impl<O: IsA<BaseButton>> BaseButtonExt for O {}
pub trait BaseButtonImpl: ButtonImpl
where
<Self as ObjectSubclass>::Type: IsA<glib::Object>,
<Self as ObjectSubclass>::Type: IsA<gtk::Widget>,
<Self as ObjectSubclass>::Type: IsA<gtk::Button>,
{
/// Default implementation of a virtual method.
///
Expand Down Expand Up @@ -91,6 +93,8 @@ where
pub trait BaseButtonImplExt: BaseButtonImpl
where
<Self as ObjectSubclass>::Type: IsA<glib::Object>,
<Self as ObjectSubclass>::Type: IsA<gtk::Widget>,
<Self as ObjectSubclass>::Type: IsA<gtk::Button>,
{
/// Retrieves the parent class' implementation of the virtual method and
/// calls it.
Expand All @@ -113,12 +117,20 @@ where
}
}

impl<T: BaseButtonImpl> BaseButtonImplExt for T where <T as ObjectSubclass>::Type: IsA<glib::Object> {}
impl<T: BaseButtonImpl> BaseButtonImplExt for T
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<gtk::Widget>,
<T as ObjectSubclass>::Type: IsA<gtk::Button>,
{
}

/// This allows to implement subclasses of `BaseButton`.
unsafe impl<T: BaseButtonImpl> IsSubclassable<T> for BaseButton
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<gtk::Widget>,
<T as ObjectSubclass>::Type: IsA<gtk::Button>,
{
/// Called whenever the class of a `BaseButton` subclass is initialized,
/// i.e. usually right before the first instance of it is created.
Expand Down
16 changes: 14 additions & 2 deletions gdk4/src/subclass/content_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::{ffi, prelude::*, subclass::prelude::*, Clipboard, ContentFormats, Co
pub trait ContentProviderImpl: ObjectImpl
where
<Self as ObjectSubclass>::Type: IsA<glib::Object>,
<Self as ObjectSubclass>::Type: IsA<ContentProvider>,
{
fn content_changed(&self) {
self.parent_content_changed()
Expand Down Expand Up @@ -50,6 +51,7 @@ where
pub trait ContentProviderImplExt: ContentProviderImpl
where
<Self as ObjectSubclass>::Type: IsA<glib::Object>,
<Self as ObjectSubclass>::Type: IsA<ContentProvider>,
{
fn parent_content_changed(&self) {
unsafe {
Expand Down Expand Up @@ -261,14 +263,17 @@ where
}
}

impl<T: ContentProviderImpl> ContentProviderImplExt for T where
<T as ObjectSubclass>::Type: IsA<glib::Object>
impl<T: ContentProviderImpl> ContentProviderImplExt for T
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<ContentProvider>,
{
}

unsafe impl<T: ContentProviderImpl> IsSubclassable<T> for ContentProvider
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<ContentProvider>,
{
fn class_init(class: &mut glib::Class<Self>) {
Self::parent_class_init::<T>(class);
Expand All @@ -289,6 +294,7 @@ unsafe extern "C" fn content_provider_content_changed<T: ContentProviderImpl>(
ptr: *mut ffi::GdkContentProvider,
) where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<ContentProvider>,
{
let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp();
Expand All @@ -301,6 +307,7 @@ unsafe extern "C" fn content_provider_attach_clipboard<T: ContentProviderImpl>(
clipboard_ptr: *mut ffi::GdkClipboard,
) where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<ContentProvider>,
{
let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp();
Expand All @@ -314,6 +321,7 @@ unsafe extern "C" fn content_provider_detach_clipboard<T: ContentProviderImpl>(
clipboard_ptr: *mut ffi::GdkClipboard,
) where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<ContentProvider>,
{
let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp();
Expand All @@ -327,6 +335,7 @@ unsafe extern "C" fn content_provider_formats<T: ContentProviderImpl>(
) -> *mut ffi::GdkContentFormats
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<ContentProvider>,
{
let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp();
Expand All @@ -339,6 +348,7 @@ unsafe extern "C" fn content_provider_storable_formats<T: ContentProviderImpl>(
) -> *mut ffi::GdkContentFormats
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<ContentProvider>,
{
let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp();
Expand All @@ -356,6 +366,7 @@ unsafe extern "C" fn content_provider_write_mime_type_async<T: ContentProviderIm
user_data: glib::ffi::gpointer,
) where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<ContentProvider>,
{
let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp();
Expand Down Expand Up @@ -418,6 +429,7 @@ unsafe extern "C" fn content_provider_get_value<T: ContentProviderImpl>(
) -> glib::ffi::gboolean
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<ContentProvider>,
{
let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp();
Expand Down
16 changes: 15 additions & 1 deletion gdk4/src/subclass/paintable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::{ffi, prelude::*, subclass::prelude::*, Paintable, PaintableFlags, Sn
pub trait PaintableImpl: ObjectImpl
where
<Self as ObjectSubclass>::Type: IsA<glib::Object>,
<Self as ObjectSubclass>::Type: IsA<Paintable>,
{
#[doc(alias = "get_current_image")]
fn current_image(&self) -> Paintable {
Expand Down Expand Up @@ -43,6 +44,7 @@ where
pub trait PaintableImplExt: PaintableImpl
where
<Self as ObjectSubclass>::Type: IsA<glib::Object>,
<Self as ObjectSubclass>::Type: IsA<Paintable>,
{
fn parent_current_image(&self) -> Paintable {
unsafe {
Expand Down Expand Up @@ -132,11 +134,17 @@ where
}
}

impl<T: PaintableImpl> PaintableImplExt for T where <T as ObjectSubclass>::Type: IsA<glib::Object> {}
impl<T: PaintableImpl> PaintableImplExt for T
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<Paintable>,
{
}

unsafe impl<T: PaintableImpl> IsImplementable<T> for Paintable
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<Paintable>,
{
fn interface_init(iface: &mut glib::Interface<Self>) {
let iface = iface.as_mut();
Expand All @@ -155,6 +163,7 @@ unsafe extern "C" fn paintable_get_current_image<T: PaintableImpl>(
) -> *mut ffi::GdkPaintable
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<Paintable>,
{
let instance = &*(paintable as *mut T::Instance);
let imp = instance.imp();
Expand All @@ -167,6 +176,7 @@ unsafe extern "C" fn paintable_get_flags<T: PaintableImpl>(
) -> ffi::GdkPaintableFlags
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<Paintable>,
{
let instance = &*(paintable as *mut T::Instance);
let imp = instance.imp();
Expand All @@ -179,6 +189,7 @@ unsafe extern "C" fn paintable_get_intrinsic_width<T: PaintableImpl>(
) -> i32
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<Paintable>,
{
let instance = &*(paintable as *mut T::Instance);
let imp = instance.imp();
Expand All @@ -191,6 +202,7 @@ unsafe extern "C" fn paintable_get_intrinsic_height<T: PaintableImpl>(
) -> i32
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<Paintable>,
{
let instance = &*(paintable as *mut T::Instance);
let imp = instance.imp();
Expand All @@ -203,6 +215,7 @@ unsafe extern "C" fn paintable_get_intrinsic_aspect_ratio<T: PaintableImpl>(
) -> f64
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<Paintable>,
{
let instance = &*(paintable as *mut T::Instance);
let imp = instance.imp();
Expand All @@ -217,6 +230,7 @@ unsafe extern "C" fn paintable_snapshot<T: PaintableImpl>(
height: f64,
) where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<Paintable>,
{
let instance = &*(paintable as *mut T::Instance);
let imp = instance.imp();
Expand Down
16 changes: 15 additions & 1 deletion gtk4/src/subclass/accessible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::{
pub trait AccessibleImpl: ObjectImpl
where
<Self as ObjectSubclass>::Type: IsA<glib::Object>,
<Self as ObjectSubclass>::Type: IsA<Accessible>,
{
#[doc(alias = "get_platform_state")]
fn platform_state(&self, state: AccessiblePlatformState) -> bool {
Expand Down Expand Up @@ -50,6 +51,7 @@ where
pub trait AccessibleImplExt: AccessibleImpl
where
<Self as ObjectSubclass>::Type: IsA<glib::Object>,
<Self as ObjectSubclass>::Type: IsA<Accessible>,
{
fn parent_platform_state(&self, state: AccessiblePlatformState) -> bool {
unsafe {
Expand Down Expand Up @@ -167,11 +169,17 @@ where
}
}

impl<T: AccessibleImpl> AccessibleImplExt for T where <T as ObjectSubclass>::Type: IsA<glib::Object> {}
impl<T: AccessibleImpl> AccessibleImplExt for T
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<Accessible>,
{
}

unsafe impl<T: AccessibleImpl> IsImplementable<T> for Accessible
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<Accessible>,
{
fn interface_init(iface: &mut glib::Interface<Self>) {
let iface = iface.as_mut();
Expand All @@ -191,6 +199,7 @@ unsafe extern "C" fn accessible_get_platform_state<T: AccessibleImpl>(
) -> glib::ffi::gboolean
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<Accessible>,
{
let instance = &*(accessible as *mut T::Instance);
let imp = instance.imp();
Expand All @@ -207,6 +216,7 @@ unsafe extern "C" fn accessible_get_bounds<T: AccessibleImpl>(
) -> glib::ffi::gboolean
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<Accessible>,
{
let instance = &*(accessible as *mut T::Instance);
let imp = instance.imp();
Expand All @@ -228,6 +238,7 @@ unsafe extern "C" fn accessible_get_at_context<T: AccessibleImpl>(
) -> *mut ffi::GtkATContext
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<Accessible>,
{
let instance = &*(accessible as *mut T::Instance);
let imp = instance.imp();
Expand All @@ -240,6 +251,7 @@ unsafe extern "C" fn accessible_get_accessible_parent<T: AccessibleImpl>(
) -> *mut ffi::GtkAccessible
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<Accessible>,
{
let instance = &*(accessible as *mut T::Instance);
let imp = instance.imp();
Expand All @@ -252,6 +264,7 @@ unsafe extern "C" fn accessible_get_first_accessible_child<T: AccessibleImpl>(
) -> *mut ffi::GtkAccessible
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<Accessible>,
{
let instance = &*(accessible as *mut T::Instance);
let imp = instance.imp();
Expand All @@ -264,6 +277,7 @@ unsafe extern "C" fn accessible_get_next_accessible_sibling<T: AccessibleImpl>(
) -> *mut ffi::GtkAccessible
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<Accessible>,
{
let instance = &*(accessible as *mut T::Instance);
let imp = instance.imp();
Expand Down
17 changes: 14 additions & 3 deletions gtk4/src/subclass/accessible_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
use glib::translate::*;

use crate::{ffi, prelude::*, subclass::prelude::*, AccessibleRange};
use crate::{ffi, prelude::*, subclass::prelude::*, AccessibleRange, Widget};

pub trait AccessibleRangeImpl: WidgetImpl
where
<Self as ObjectSubclass>::Type: IsA<glib::Object>,
<Self as ObjectSubclass>::Type: IsA<Widget>,
<Self as ObjectSubclass>::Type: IsA<AccessibleRange>,
{
fn set_current_value(&self, value: f64) -> bool {
self.parent_set_current_value(value)
Expand All @@ -20,6 +22,8 @@ where
pub trait AccessibleRangeImplExt: AccessibleRangeImpl
where
<Self as ObjectSubclass>::Type: IsA<glib::Object>,
<Self as ObjectSubclass>::Type: IsA<Widget>,
<Self as ObjectSubclass>::Type: IsA<AccessibleRange>,
{
// Returns true if the operation was performed, false otherwise
fn parent_set_current_value(&self, value: f64) -> bool {
Expand All @@ -43,14 +47,19 @@ where
}
}

impl<T: AccessibleRangeImpl> AccessibleRangeImplExt for T where
<T as ObjectSubclass>::Type: IsA<glib::Object>
impl<T: AccessibleRangeImpl> AccessibleRangeImplExt for T
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<Widget>,
<T as ObjectSubclass>::Type: IsA<AccessibleRange>,
{
}

unsafe impl<T: AccessibleRangeImpl> IsImplementable<T> for AccessibleRange
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<Widget>,
<T as ObjectSubclass>::Type: IsA<AccessibleRange>,
{
fn interface_init(iface: &mut glib::Interface<Self>) {
let iface = iface.as_mut();
Expand All @@ -65,6 +74,8 @@ unsafe extern "C" fn accessible_range_set_current_value<T: AccessibleRangeImpl>(
) -> glib::ffi::gboolean
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
<T as ObjectSubclass>::Type: IsA<Widget>,
<T as ObjectSubclass>::Type: IsA<AccessibleRange>,
{
let instance = &*(accessible_range as *mut T::Instance);
let imp = instance.imp();
Expand Down
Loading

0 comments on commit d50724f

Please sign in to comment.