Attribute Macro glib_macros::object_subclass

source ·
#[object_subclass]
Expand description

Macro for boilerplate of ObjectSubclass implementations.

This adds implementations for the type_data() and type_() methods, which should probably never be defined differently.

It provides default values for the Instance, Class, and Interfaces type parameters. If these are present, the macro will use the provided value instead of the default.

Usually the defaults for Instance and Class will work. Interfaces is necessary for types that implement interfaces.

type Instance = glib::subclass::basic::InstanceStruct<Self>;
type Class = glib::subclass::basic::ClassStruct<Self>;
type Interfaces = ();

If no new() or with_class() method is provide, the macro adds a new() implementation calling Default::default(). So the type needs to implement Default, or this should be overridden.

fn new() -> Self {
    Default::default()
}