pub trait ObjectSubclass:
Sized
+ ObjectSubclassType
+ 'static {
type Type: ObjectType + ObjectSubclassIs<Subclass = Self> + FromGlibPtrFull<*mut <Self::Type as ObjectType>::GlibType> + FromGlibPtrBorrow<*mut <Self::Type as ObjectType>::GlibType> + FromGlibPtrNone<*mut <Self::Type as ObjectType>::GlibType>;
type ParentType: IsSubclassable<Self> + FromGlibPtrFull<*mut <Self::ParentType as ObjectType>::GlibType> + FromGlibPtrBorrow<*mut <Self::ParentType as ObjectType>::GlibType> + FromGlibPtrNone<*mut <Self::ParentType as ObjectType>::GlibType>;
type Interfaces: InterfaceList<Self>;
type Instance: InstanceStruct<Type = Self>;
type Class: ClassStruct<Type = Self>;
const NAME: &'static str;
const ABSTRACT: bool = false;
const ALLOW_NAME_CONFLICT: bool = false;
// Provided methods
fn type_init(_type_: &mut InitializingType<Self>) { ... }
fn class_init(_klass: &mut Self::Class) { ... }
fn new() -> Self { ... }
fn with_class(_klass: &Self::Class) -> Self { ... }
fn instance_init(_obj: &InitializingObject<Self>) { ... }
}
Expand description
The central trait for subclassing a GObject
type.
Links together the type name, parent type and the instance and class structs for type registration and allows subclasses to hook into various steps of the type registration and initialization.
See register_type
for registering an implementation of this trait
with the type system.
Required Associated Constants§
Provided Associated Constants§
sourceconst ABSTRACT: bool = false
const ABSTRACT: bool = false
If this subclass is an abstract class or not.
By default, all subclasses are non-abstract types but setting this to true
will create an
abstract class instead.
Abstract classes can’t be instantiated and require a non-abstract subclass.
Optional.
sourceconst ALLOW_NAME_CONFLICT: bool = false
const ALLOW_NAME_CONFLICT: bool = false
Allow name conflicts for this class.
By default, trying to register a type with a name that was registered before will panic. If
this is set to true
then a new name will be selected by appending a counter.
This is useful for defining new types in Rust library crates that might be linked multiple times in the same process.
A consequence of setting this to true
is that it’s not guaranteed that
glib::Type::from_name(Self::NAME).unwrap() == Self::type_()
.
Note that this is not allowed for dynamic types. If a dynamic type is registered and a type with that name exists already, it is assumed that they’re the same.
Optional.
Required Associated Types§
sourcetype Type: ObjectType + ObjectSubclassIs<Subclass = Self> + FromGlibPtrFull<*mut <Self::Type as ObjectType>::GlibType> + FromGlibPtrBorrow<*mut <Self::Type as ObjectType>::GlibType> + FromGlibPtrNone<*mut <Self::Type as ObjectType>::GlibType>
type Type: ObjectType + ObjectSubclassIs<Subclass = Self> + FromGlibPtrFull<*mut <Self::Type as ObjectType>::GlibType> + FromGlibPtrBorrow<*mut <Self::Type as ObjectType>::GlibType> + FromGlibPtrNone<*mut <Self::Type as ObjectType>::GlibType>
Wrapper around this subclass defined with wrapper!
sourcetype ParentType: IsSubclassable<Self> + FromGlibPtrFull<*mut <Self::ParentType as ObjectType>::GlibType> + FromGlibPtrBorrow<*mut <Self::ParentType as ObjectType>::GlibType> + FromGlibPtrNone<*mut <Self::ParentType as ObjectType>::GlibType>
type ParentType: IsSubclassable<Self> + FromGlibPtrFull<*mut <Self::ParentType as ObjectType>::GlibType> + FromGlibPtrBorrow<*mut <Self::ParentType as ObjectType>::GlibType> + FromGlibPtrNone<*mut <Self::ParentType as ObjectType>::GlibType>
Parent Rust type to inherit from.
sourcetype Interfaces: InterfaceList<Self>
type Interfaces: InterfaceList<Self>
List of interfaces implemented by this type.
sourcetype Instance: InstanceStruct<Type = Self>
type Instance: InstanceStruct<Type = Self>
The C instance struct.
See basic::InstanceStruct
for an basic instance struct that should be
used in most cases.
sourcetype Class: ClassStruct<Type = Self>
type Class: ClassStruct<Type = Self>
The C class struct.
See basic::ClassStruct
for an basic class struct that should be
used in most cases.
Provided Methods§
sourcefn type_init(_type_: &mut InitializingType<Self>)
fn type_init(_type_: &mut InitializingType<Self>)
Additional type initialization.
This is called right after the type was registered and allows
subclasses to do additional type-specific initialization, e.g.
for implementing GObject
interfaces.
Optional
sourcefn class_init(_klass: &mut Self::Class)
fn class_init(_klass: &mut Self::Class)
Class initialization.
This is called after type_init
and before the first instance
of the subclass is created. Subclasses can use this to do class-
specific initialization, e.g. for registering signals on the class
or calling class methods.
Optional
sourcefn new() -> Self
fn new() -> Self
Constructor.
This is called during object instantiation before further subclasses are initialized, and should return a new instance of the subclass private struct.
Optional, either implement this or with_class()
.
sourcefn with_class(_klass: &Self::Class) -> Self
fn with_class(_klass: &Self::Class) -> Self
Constructor.
This is called during object instantiation before further subclasses are initialized, and should return a new instance of the subclass private struct.
Different to new()
above it also gets the class of this type passed
to itself for providing additional context.
Optional, either implement this or new()
.
sourcefn instance_init(_obj: &InitializingObject<Self>)
fn instance_init(_obj: &InitializingObject<Self>)
Performs additional instance initialization.
Called just after with_class()
. At this point the initialization has not completed yet, so
only a limited set of operations is safe (see InitializingObject
).
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.