Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Commit

Permalink
In glib_object_wrapper!, use generic Class type instead defining a st…
Browse files Browse the repository at this point in the history
…ruct

This makes the `$rust_class_name` argument in `glib_wrapper!` optional.
If specified, it defines a `type` alias for the class. At least
optionally allowing it is required to avoid breaking lots of gir
generated code, but perhaps it can be removed after a change to gir.

This removes the `ObjectType::RustClassType` associated type, since it
can't be enforced/assumed by the type system that that is an instance of
this generic struct.

The `IsClassFor` trait is also removed, superseded by this generic
type.

This also changes the `IsSubclassable` trait to be implemented on the
object struct rather than the class struct, since there otherwise would
be foreign trait on foreign type errors.
  • Loading branch information
ids1024 committed Nov 4, 2020
1 parent 584b990 commit 3e29094
Show file tree
Hide file tree
Showing 42 changed files with 348 additions and 380 deletions.
2 changes: 1 addition & 1 deletion examples/src/bin/basic_subclass.rs
Expand Up @@ -113,7 +113,7 @@ mod imp_win {
}

glib_wrapper! {
pub struct SimpleWindow(ObjectSubclass<imp_win::SimpleWindow, SimpleWindowClass>)
pub struct SimpleWindow(ObjectSubclass<imp_win::SimpleWindow>)
@extends gtk::Widget, gtk::Container, gtk::Bin, gtk::Window, gtk::ApplicationWindow;
}

Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/listbox_model.rs
Expand Up @@ -319,7 +319,7 @@ mod row_data {
// Public part of the RowData type. This behaves like a normal gtk-rs-style GObject
// binding
glib_wrapper! {
pub struct RowData(ObjectSubclass<imp::RowData, RowDataClass>);
pub struct RowData(ObjectSubclass<imp::RowData>);
}

// Constructor for new instances. This simply calls glib::Object::new() with
Expand Down
8 changes: 4 additions & 4 deletions gio/src/subclass/application.rs
Expand Up @@ -303,11 +303,11 @@ impl<T: ApplicationImpl> ApplicationImplExt for T {
}
}

unsafe impl<T: ApplicationImpl> IsSubclassable<T> for ApplicationClass {
fn override_vfuncs(&mut self) {
<glib::ObjectClass as IsSubclassable<T>>::override_vfuncs(self);
unsafe impl<T: ApplicationImpl> IsSubclassable<T> for Application {
fn override_vfuncs(class: &mut ::glib::object::Class<Self>) {
<glib::Object as IsSubclassable<T>>::override_vfuncs(class);
unsafe {
let klass = &mut *(self as *mut Self as *mut gio_sys::GApplicationClass);
let klass = &mut *(class as *mut _ as *mut gio_sys::GApplicationClass);
klass.activate = Some(application_activate::<T>);
klass.after_emit = Some(application_after_emit::<T>);
klass.before_emit = Some(application_before_emit::<T>);
Expand Down
8 changes: 4 additions & 4 deletions gio/src/subclass/input_stream.rs
Expand Up @@ -151,11 +151,11 @@ impl<T: InputStreamImpl> InputStreamImplExt for T {
}
}

unsafe impl<T: InputStreamImpl> IsSubclassable<T> for InputStreamClass {
fn override_vfuncs(&mut self) {
<glib::ObjectClass as IsSubclassable<T>>::override_vfuncs(self);
unsafe impl<T: InputStreamImpl> IsSubclassable<T> for InputStream {
fn override_vfuncs(class: &mut ::glib::object::Class<Self>) {
<glib::Object as IsSubclassable<T>>::override_vfuncs(class);
unsafe {
let klass = &mut *(self as *mut Self as *mut gio_sys::GInputStreamClass);
let klass = &mut *(class as *mut _ as *mut gio_sys::GInputStreamClass);
klass.read_fn = Some(stream_read::<T>);
klass.close_fn = Some(stream_close::<T>);
klass.skip = Some(stream_skip::<T>);
Expand Down
8 changes: 4 additions & 4 deletions gio/src/subclass/io_stream.rs
Expand Up @@ -95,11 +95,11 @@ impl<T: IOStreamImpl> IOStreamImplExt for T {
}
}

unsafe impl<T: IOStreamImpl> IsSubclassable<T> for IOStreamClass {
fn override_vfuncs(&mut self) {
<glib::ObjectClass as IsSubclassable<T>>::override_vfuncs(self);
unsafe impl<T: IOStreamImpl> IsSubclassable<T> for IOStream {
fn override_vfuncs(class: &mut ::glib::object::Class<Self>) {
<glib::Object as IsSubclassable<T>>::override_vfuncs(class);
unsafe {
let klass = &mut *(self as *mut Self as *mut gio_sys::GIOStreamClass);
let klass = &mut *(class as *mut _ as *mut gio_sys::GIOStreamClass);
klass.get_input_stream = Some(stream_get_input_stream::<T>);
klass.get_output_stream = Some(stream_get_output_stream::<T>);
klass.close_fn = Some(stream_close::<T>);
Expand Down
8 changes: 4 additions & 4 deletions gio/src/subclass/output_stream.rs
Expand Up @@ -191,11 +191,11 @@ impl<T: OutputStreamImpl> OutputStreamImplExt for T {
}
}

unsafe impl<T: OutputStreamImpl> IsSubclassable<T> for OutputStreamClass {
fn override_vfuncs(&mut self) {
<glib::ObjectClass as IsSubclassable<T>>::override_vfuncs(self);
unsafe impl<T: OutputStreamImpl> IsSubclassable<T> for OutputStream {
fn override_vfuncs(class: &mut ::glib::object::Class<Self>) {
<glib::Object as IsSubclassable<T>>::override_vfuncs(class);
unsafe {
let klass = &mut *(self as *mut Self as *mut gio_sys::GOutputStreamClass);
let klass = &mut *(class as *mut _ as *mut gio_sys::GOutputStreamClass);
klass.write_fn = Some(stream_write::<T>);
klass.close_fn = Some(stream_close::<T>);
klass.flush = Some(stream_flush::<T>);
Expand Down
4 changes: 2 additions & 2 deletions glib/src/lib.rs
Expand Up @@ -104,8 +104,8 @@ pub use closure::Closure;
pub use error::{BoolError, Error};
pub use file_error::FileError;
pub use object::{
Cast, InitiallyUnowned, InitiallyUnownedClass, IsA, IsClassFor, Object, ObjectClass, ObjectExt,
ObjectType, SendWeakRef, WeakRef,
Cast, InitiallyUnowned, InitiallyUnownedClass, IsA, Object, ObjectClass, ObjectExt, ObjectType,
SendWeakRef, WeakRef,
};
pub use signal::{
signal_handler_block, signal_handler_disconnect, signal_handler_unblock,
Expand Down

0 comments on commit 3e29094

Please sign in to comment.