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 authored and bilelmoussaoui committed Oct 18, 2024
1 parent adf5b72 commit a65c21f
Show file tree
Hide file tree
Showing 67 changed files with 164 additions and 442 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.

2 changes: 1 addition & 1 deletion examples/virtual_methods/base_button/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ 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 + ObjectSubclass<Type: IsA<BaseButton>> {
/// Default implementation of a virtual method.
///
/// This always calls into the implementation of the parent class so that if
Expand Down
9 changes: 2 additions & 7 deletions gdk4/src/subclass/content_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use glib::{translate::*, Value};

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

pub trait ContentProviderImpl: ContentProviderImplExt + ObjectImpl {
pub trait ContentProviderImpl: ObjectImpl + ObjectSubclass<Type: IsA<ContentProvider>> {
fn content_changed(&self) {
self.parent_content_changed()
}
Expand Down Expand Up @@ -44,12 +44,7 @@ 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 {
fn parent_content_changed(&self) {
unsafe {
let data = Self::type_data();
Expand Down
9 changes: 2 additions & 7 deletions gdk4/src/subclass/paintable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use glib::translate::*;

use crate::{ffi, prelude::*, subclass::prelude::*, Paintable, PaintableFlags, Snapshot};

pub trait PaintableImpl: PaintableImplExt + ObjectImpl {
pub trait PaintableImpl: ObjectImpl + ObjectSubclass<Type: IsA<Paintable>> {
#[doc(alias = "get_current_image")]
fn current_image(&self) -> Paintable {
self.parent_current_image()
Expand Down Expand Up @@ -37,12 +37,7 @@ pub trait PaintableImpl: PaintableImplExt + ObjectImpl {
fn snapshot(&self, snapshot: &Snapshot, width: f64, height: f64);
}

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

pub trait PaintableImplExt: sealed::Sealed + ObjectSubclass {
pub trait PaintableImplExt: PaintableImpl {
fn parent_current_image(&self) -> Paintable {
unsafe {
let type_data = Self::type_data();
Expand Down
9 changes: 2 additions & 7 deletions gtk4/src/subclass/accessible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
ffi, prelude::*, subclass::prelude::*, ATContext, Accessible, AccessiblePlatformState,
};

pub trait AccessibleImpl: ObjectImpl {
pub trait AccessibleImpl: ObjectImpl + ObjectSubclass<Type: IsA<Accessible>> {
#[doc(alias = "get_platform_state")]
fn platform_state(&self, state: AccessiblePlatformState) -> bool {
self.parent_platform_state(state)
Expand Down Expand Up @@ -44,12 +44,7 @@ pub trait AccessibleImpl: ObjectImpl {
}
}

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

pub trait AccessibleImplExt: sealed::Sealed + ObjectSubclass {
pub trait AccessibleImplExt: AccessibleImpl {
fn parent_platform_state(&self, state: AccessiblePlatformState) -> bool {
unsafe {
let type_data = Self::type_data();
Expand Down
9 changes: 2 additions & 7 deletions gtk4/src/subclass/accessible_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,13 @@ use glib::translate::*;

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

pub trait AccessibleRangeImpl: WidgetImpl {
pub trait AccessibleRangeImpl: AccessibleImpl + ObjectSubclass<Type: IsA<AccessibleRange>> {
fn set_current_value(&self, value: f64) -> bool {
self.parent_set_current_value(value)
}
}

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

pub trait AccessibleRangeImplExt: sealed::Sealed + ObjectSubclass {
pub trait AccessibleRangeImplExt: AccessibleRangeImpl {
// Returns true if the operation was performed, false otherwise
fn parent_set_current_value(&self, value: f64) -> bool {
unsafe {
Expand Down
9 changes: 2 additions & 7 deletions gtk4/src/subclass/actionable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use glib::{translate::*, GString, Variant};

use crate::{ffi, prelude::*, subclass::prelude::*, Actionable};

pub trait ActionableImpl: WidgetImpl {
pub trait ActionableImpl: WidgetImpl + ObjectSubclass<Type: IsA<Actionable>> {
#[doc(alias = "get_action_name")]
fn action_name(&self) -> Option<GString>;
#[doc(alias = "get_action_target_value")]
Expand All @@ -17,12 +17,7 @@ pub trait ActionableImpl: WidgetImpl {
fn set_action_target_value(&self, value: Option<&Variant>);
}

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

pub trait ActionableImplExt: sealed::Sealed + ObjectSubclass {
pub trait ActionableImplExt: ActionableImpl {
fn parent_action_name(&self) -> Option<GString> {
unsafe {
let type_data = Self::type_data();
Expand Down
9 changes: 2 additions & 7 deletions gtk4/src/subclass/adjustment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use glib::translate::*;

use crate::{ffi, prelude::*, subclass::prelude::*, Adjustment};

pub trait AdjustmentImpl: AdjustmentImplExt + ObjectImpl {
pub trait AdjustmentImpl: ObjectImpl + ObjectSubclass<Type: IsA<Adjustment>> {
fn changed(&self) {
self.parent_changed()
}
Expand All @@ -17,12 +17,7 @@ pub trait AdjustmentImpl: AdjustmentImplExt + ObjectImpl {
}
}

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

pub trait AdjustmentImplExt: sealed::Sealed + ObjectSubclass {
pub trait AdjustmentImplExt: AdjustmentImpl {
fn parent_changed(&self) {
unsafe {
let data = Self::type_data();
Expand Down
9 changes: 2 additions & 7 deletions gtk4/src/subclass/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use glib::translate::*;

use crate::{ffi, prelude::*, subclass::prelude::*, Application, Window};

pub trait GtkApplicationImpl: GtkApplicationImplExt + ApplicationImpl {
pub trait GtkApplicationImpl: ApplicationImpl + ObjectSubclass<Type: IsA<Application>> {
fn window_added(&self, window: &Window) {
self.parent_window_added(window)
}
Expand All @@ -17,12 +17,7 @@ pub trait GtkApplicationImpl: GtkApplicationImplExt + ApplicationImpl {
}
}

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

pub trait GtkApplicationImplExt: sealed::Sealed + ObjectSubclass {
pub trait GtkApplicationImplExt: GtkApplicationImpl {
fn parent_window_added(&self, window: &Window) {
unsafe {
let data = Self::type_data();
Expand Down
7 changes: 5 additions & 2 deletions gtk4/src/subclass/application_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
//! Traits intended for subclassing
//! [`ApplicationWindow`](crate::ApplicationWindow).

use crate::{subclass::prelude::*, ApplicationWindow};
use crate::{prelude::*, subclass::prelude::*, ApplicationWindow};

pub trait ApplicationWindowImpl: WindowImpl + 'static {}
pub trait ApplicationWindowImpl:
WindowImpl + ObjectSubclass<Type: IsA<ApplicationWindow>> + 'static
{
}

unsafe impl<T: ApplicationWindowImpl> IsSubclassable<T> for ApplicationWindow {}
4 changes: 2 additions & 2 deletions gtk4/src/subclass/box_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// rustdoc-stripper-ignore-next
//! Traits intended for subclassing [`Box`](crate::Box).

use crate::{subclass::prelude::*, Box};
use crate::{prelude::*, subclass::prelude::*, Box};

pub trait BoxImpl: WidgetImpl {}
pub trait BoxImpl: WidgetImpl + ObjectSubclass<Type: IsA<Box>> {}

unsafe impl<T: BoxImpl> IsSubclassable<T> for Box {}
9 changes: 2 additions & 7 deletions gtk4/src/subclass/buildable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use glib::{translate::*, GString, Object, Quark, Value};
use super::PtrHolder;
use crate::{ffi, prelude::*, subclass::prelude::*, Buildable, Builder};

pub trait BuildableImpl: ObjectImpl {
pub trait BuildableImpl: ObjectImpl + ObjectSubclass<Type: IsA<Buildable>> {
fn set_id(&self, id: &str) {
self.parent_set_id(id)
}
Expand Down Expand Up @@ -59,12 +59,7 @@ pub trait BuildableImpl: ObjectImpl {
// );
}

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

pub trait BuildableImplExt: sealed::Sealed + ObjectSubclass {
pub trait BuildableImplExt: BuildableImpl {
fn parent_set_id(&self, id: &str) {
unsafe {
let type_data = Self::type_data();
Expand Down
11 changes: 3 additions & 8 deletions gtk4/src/subclass/builder_scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ use crate::{
BuilderScope,
};

pub trait BuilderCScopeImpl: BuilderScopeImpl {}
pub trait BuilderCScopeImpl: BuilderScopeImpl + ObjectSubclass<Type: IsA<BuilderCScope>> {}

unsafe impl<T: BuilderCScopeImpl> IsSubclassable<T> for BuilderCScope {}

pub trait BuilderScopeImpl: ObjectImpl {
pub trait BuilderScopeImpl: ObjectImpl + ObjectSubclass<Type: IsA<BuilderScope>> {
#[doc(alias = "get_type_from_name")]
fn type_from_name(&self, builder: &Builder, type_name: &str) -> glib::Type {
self.parent_type_from_name(builder, type_name)
Expand All @@ -35,12 +35,7 @@ pub trait BuilderScopeImpl: ObjectImpl {
) -> Result<glib::Closure, glib::Error>;
}

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

pub trait BuilderScopeImplExt: sealed::Sealed + ObjectSubclass {
pub trait BuilderScopeImplExt: BuilderScopeImpl {
fn parent_type_from_name(&self, builder: &Builder, type_name: &str) -> glib::Type {
unsafe {
let type_data = Self::type_data();
Expand Down
Loading

0 comments on commit a65c21f

Please sign in to comment.