Skip to content

Commit

Permalink
Add newly required trait bounds from core
Browse files Browse the repository at this point in the history
  • Loading branch information
felinira committed Oct 3, 2024
1 parent b6d56d7 commit 739e2fa
Show file tree
Hide file tree
Showing 67 changed files with 2,012 additions and 843 deletions.
32 changes: 16 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 13 additions & 4 deletions examples/virtual_methods/base_button/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ impl<O: IsA<BaseButton>> BaseButtonExt for O {}
/// implement.
///
/// See `derived_button/imp.rs` for how to override virtual methods.
pub trait BaseButtonImpl: ButtonImpl {
pub trait BaseButtonImpl: ButtonImpl
where
<Self as ObjectSubclass>::Type: IsA<glib::Object>,
{
/// Default implementation of a virtual method.
///
/// This always calls into the implementation of the parent class so that if
Expand All @@ -85,7 +88,10 @@ pub trait BaseButtonImpl: ButtonImpl {
///
/// These are supposed to be called only from inside implementations of
/// `BaseButton` subclasses.
pub trait BaseButtonImplExt: BaseButtonImpl {
pub trait BaseButtonImplExt: BaseButtonImpl
where
<Self as ObjectSubclass>::Type: IsA<glib::Object>,
{
/// Retrieves the parent class' implementation of the virtual method and
/// calls it.
fn parent_sync_method(&self, extra_text: Option<&str>) {
Expand All @@ -107,10 +113,13 @@ pub trait BaseButtonImplExt: BaseButtonImpl {
}
}

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

/// This allows to implement subclasses of `BaseButton`.
unsafe impl<T: BaseButtonImpl> IsSubclassable<T> for BaseButton {
unsafe impl<T: BaseButtonImpl> IsSubclassable<T> for BaseButton
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
{
/// Called whenever the class of a `BaseButton` subclass is initialized,
/// i.e. usually right before the first instance of it is created.
fn class_init(class: &mut glib::Class<Self>) {
Expand Down
56 changes: 40 additions & 16 deletions gdk4/src/subclass/content_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ use glib::{translate::*, Value};

use crate::{ffi, prelude::*, subclass::prelude::*, Clipboard, ContentFormats, ContentProvider};

pub trait ContentProviderImpl: ContentProviderImplExt + ObjectImpl {
pub trait ContentProviderImpl: ObjectImpl
where
<Self as ObjectSubclass>::Type: IsA<glib::Object>,
{
fn content_changed(&self) {
self.parent_content_changed()
}
Expand Down Expand Up @@ -44,12 +47,10 @@ pub trait ContentProviderImpl: ContentProviderImplExt + ObjectImpl {
}
}

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

pub trait ContentProviderImplExt: sealed::Sealed + ObjectSubclass {
pub trait ContentProviderImplExt: ContentProviderImpl
where
<Self as ObjectSubclass>::Type: IsA<glib::Object>,
{
fn parent_content_changed(&self) {
unsafe {
let data = Self::type_data();
Expand Down Expand Up @@ -260,9 +261,15 @@ pub trait ContentProviderImplExt: sealed::Sealed + ObjectSubclass {
}
}

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

unsafe impl<T: ContentProviderImpl> IsSubclassable<T> for ContentProvider {
unsafe impl<T: ContentProviderImpl> IsSubclassable<T> for ContentProvider
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
{
fn class_init(class: &mut glib::Class<Self>) {
Self::parent_class_init::<T>(class);

Expand All @@ -280,7 +287,9 @@ unsafe impl<T: ContentProviderImpl> IsSubclassable<T> for ContentProvider {

unsafe extern "C" fn content_provider_content_changed<T: ContentProviderImpl>(
ptr: *mut ffi::GdkContentProvider,
) {
) where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
{
let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp();

Expand All @@ -290,7 +299,9 @@ unsafe extern "C" fn content_provider_content_changed<T: ContentProviderImpl>(
unsafe extern "C" fn content_provider_attach_clipboard<T: ContentProviderImpl>(
ptr: *mut ffi::GdkContentProvider,
clipboard_ptr: *mut ffi::GdkClipboard,
) {
) where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
{
let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp();
let clipboard = from_glib_borrow(clipboard_ptr);
Expand All @@ -301,7 +312,9 @@ unsafe extern "C" fn content_provider_attach_clipboard<T: ContentProviderImpl>(
unsafe extern "C" fn content_provider_detach_clipboard<T: ContentProviderImpl>(
ptr: *mut ffi::GdkContentProvider,
clipboard_ptr: *mut ffi::GdkClipboard,
) {
) where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
{
let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp();
let clipboard = from_glib_borrow(clipboard_ptr);
Expand All @@ -311,7 +324,10 @@ unsafe extern "C" fn content_provider_detach_clipboard<T: ContentProviderImpl>(

unsafe extern "C" fn content_provider_formats<T: ContentProviderImpl>(
ptr: *mut ffi::GdkContentProvider,
) -> *mut ffi::GdkContentFormats {
) -> *mut ffi::GdkContentFormats
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
{
let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp();

Expand All @@ -320,7 +336,10 @@ unsafe extern "C" fn content_provider_formats<T: ContentProviderImpl>(

unsafe extern "C" fn content_provider_storable_formats<T: ContentProviderImpl>(
ptr: *mut ffi::GdkContentProvider,
) -> *mut ffi::GdkContentFormats {
) -> *mut ffi::GdkContentFormats
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
{
let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp();

Expand All @@ -335,7 +354,9 @@ unsafe extern "C" fn content_provider_write_mime_type_async<T: ContentProviderIm
cancellable_ptr: *mut gio::ffi::GCancellable,
callback: gio::ffi::GAsyncReadyCallback,
user_data: glib::ffi::gpointer,
) {
) where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
{
let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp();
let wrap: ContentProvider = from_glib_none(ptr);
Expand Down Expand Up @@ -394,7 +415,10 @@ unsafe extern "C" fn content_provider_get_value<T: ContentProviderImpl>(
ptr: *mut ffi::GdkContentProvider,
value_ptr: *mut glib::gobject_ffi::GValue,
error_ptr: *mut *mut glib::ffi::GError,
) -> glib::ffi::gboolean {
) -> glib::ffi::gboolean
where
<T as ObjectSubclass>::Type: IsA<glib::Object>,
{
let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp();
let value: Value = from_glib_none(value_ptr);
Expand Down
Loading

0 comments on commit 739e2fa

Please sign in to comment.