diff --git a/examples/virtual_methods/cat.rs b/examples/virtual_methods/cat.rs index 1c26639f0e69..7bca2b4862d9 100644 --- a/examples/virtual_methods/cat.rs +++ b/examples/virtual_methods/cat.rs @@ -96,7 +96,17 @@ impl Default for Cat { /// /// By convention we still create an empty `CatImpl` trait, this allows us to add /// 'protected' cat methods only available to be called by other Cats later. -pub trait CatImpl: PetImpl {} +pub trait CatImpl: PetImpl +where + ::Type: IsA, + ::Type: IsA, +{ +} /// To make this class subclassable we need to implement IsSubclassable -unsafe impl IsSubclassable for Cat {} +unsafe impl IsSubclassable for Cat +where + ::Type: IsA, + ::Type: IsA, +{ +} diff --git a/examples/virtual_methods/pet.rs b/examples/virtual_methods/pet.rs index a8aa7c692044..aa83b95b5bcb 100644 --- a/examples/virtual_methods/pet.rs +++ b/examples/virtual_methods/pet.rs @@ -125,7 +125,10 @@ pub trait PetExt: IsA { impl> PetExt for T {} /// The `PetImpl` trait contains overridable virtual function definitions for [`Pet`] objects. -pub trait PetImpl: ObjectImpl { +pub trait PetImpl: ObjectImpl +where + ::Type: IsA, +{ /// Default implementation of a virtual method. /// /// This always calls into the implementation of the parent class so that if @@ -148,7 +151,10 @@ pub trait PetImpl: ObjectImpl { /// The `PetImplExt` trait contains non-overridable methods for subclasses to use. /// /// These are supposed to be called only from inside implementations of `Pet` subclasses. -pub trait PetImplExt: PetImpl { +pub trait PetImplExt: PetImpl +where + ::Type: IsA, +{ /// Chains up to the parent implementation of [`PetImpl::pet`] fn parent_pet(&self) -> bool { let data = Self::type_data(); @@ -169,10 +175,13 @@ pub trait PetImplExt: PetImpl { } /// The `PetImplExt` trait is implemented for all subclasses that have [`Pet`] in the class hierarchy -impl PetImplExt for T {} +impl PetImplExt for T where ::Type: IsA {} /// To make this class subclassable we need to implement IsSubclassable -unsafe impl IsSubclassable for Pet { +unsafe impl IsSubclassable for Pet +where + ::Type: IsA, +{ /// Override the virtual method function pointers in subclasses to call directly into the /// `PetImpl` of the subclass. /// diff --git a/examples/virtual_methods/purrable.rs b/examples/virtual_methods/purrable.rs index d900b480a019..cb88785f3522 100644 --- a/examples/virtual_methods/purrable.rs +++ b/examples/virtual_methods/purrable.rs @@ -82,7 +82,10 @@ pub trait PurrableExt: IsA { impl> PurrableExt for T {} /// The `PurrableImpl` trait contains virtual function definitions for [`Purrable`] objects. -pub trait PurrableImpl: ObjectImpl { +pub trait PurrableImpl: ObjectImpl +where + ::Type: IsA, +{ /// Return the current purring status. /// /// The default implementation chains up to the parent implementation, @@ -96,7 +99,10 @@ pub trait PurrableImpl: ObjectImpl { /// The `PurrableImplExt` trait contains non-overridable methods for subclasses to use. /// /// These are supposed to be called only from inside implementations of `Pet` subclasses. -pub trait PurrableImplExt: PurrableImpl { +pub trait PurrableImplExt: PurrableImpl +where + ::Type: IsA, +{ /// Chains up to the parent implementation of [`PurrableExt::is_purring`] fn parent_is_purring(&self) -> bool { let data = Self::type_data(); @@ -109,10 +115,13 @@ pub trait PurrableImplExt: PurrableImpl { } /// The `PurrableImplExt` trait is implemented for all classes that implement [`Purrable`]. -impl PurrableImplExt for T {} +impl PurrableImplExt for T where ::Type: IsA {} /// To make this interface implementable we need to implement [`IsImplementable`] -unsafe impl IsImplementable for Purrable { +unsafe impl IsImplementable for Purrable +where + ::Type: IsA, +{ fn interface_init(iface: &mut glib::Interface) { let klass = iface.as_mut();