# ferro_class

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-base/macro-ferro_class/

**macro** · [`ferroui-base`](/docs/0.5.0/api/ferroui-base/) · v0.5.0

```rust
macro_rules! ferro_class
```

Declares a class.

```ignore
#[repr(C)]
pub struct Decorator { base: Control, /* fields */ }

// A class without new virtual members:
ferro_class!(Decorator: Control);

// A class that introduces virtual members:
ferro_class! {
    Layoutable: Visual, virtuals LayoutableImpl: VisualImpl {
        /// Measures the control.
        fn measure_override(this, available_size: Size) -> Size;
        fn arrange_override(this, final_size: Size) -> Size;
    }
}
```

Both forms generate `Deref<Target = Base>`, [`Upcast`](/docs/0.5.0/api/ferroui-base/trait-upcast/) to every ancestor,
the `TYPE` runtime type and [`ObjectType`](/docs/0.5.0/api/ferroui-base/trait-objecttype/), including the static
initialisation of the class (`ObjectType::register_class`). What the
initialisation does is taken from the other declarations of the class,
each optional and found by the macro without being named here:

* `ferro_properties! { impl Decorator { .. } }`, the property definitions;
* `fn static_constructor()`, an inherent function declared in the same
  module (`ClassDefaults::static_constructor`);
* `ferro_class_info!(Decorator { new: Decorator::new, interfaces: [..] })`,
  the default constructor and the interface handles the class converts
  to.

The second form also generates:

* `LayoutableVTable`, the table of the new members;
* `trait LayoutableImpl`, with one associated function per member taking
  `this: &Self`. Every class deriving from `Layoutable` implements it
  (`impl LayoutableImpl for Border {}`) and overrides what it needs
  (`ferro_impl_classes!` and `ferro_overrides!` write the same
  implementation and state what it overrides, which shortens the calls);
* `LayoutableImplExt::parent_<member>`, to call the base implementation
  from an override;
* `Layoutable::<member>(&self, ..)`, which performs the virtual call.

The declaring class must implement every member itself; these are the
base implementations.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/type_system.rs#L1278)

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
