# TypeInfo

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-base/struct-typeinfo/

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

```rust
struct TypeInfo
```

Describes a class (or a non-instantiable type that owns attached
properties): its name, where it is declared, its base class, how to
initialise it and how to create an instance of it.

A `TypeInfo` is plain constant data, built by `ferro_class!` and
`ferro_static_type!`.

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

## Members

- [`new`](#function-new)
- [`with_identity`](#function-with_identity)
- [`identity`](#function-identity)
- [`derives_from`](#function-derives_from)
- [`with_module_path`](#function-with_module_path)
- [`with_class_init`](#function-with_class_init)
- [`with_constructor`](#function-with_constructor)
- [`with_handles`](#function-with_handles)
- [`with_handle_registration`](#function-with_handle_registration)
- [`with_interfaces`](#function-with_interfaces)
- [`with_markup`](#function-with_markup)
- [`name`](#function-name)
- [`base_type`](#function-base_type)
- [`module_path`](#function-module_path)
- [`namespace`](#function-namespace)
- [`namespace_of_module`](#function-namespace_of_module)
- [`full_name`](#function-full_name)
- [`ensure_class_init`](#function-ensure_class_init)
- [`default_constructor`](#function-default_constructor)
- [`create_instance`](#function-create_instance)
- [`register_constructor`](#function-register_constructor)
- [`handle`](#function-handle)
- [`nullable_handle`](#function-nullable_handle)
- [`interfaces`](#function-interfaces)
- [`markup`](#function-markup)
- [`content_property`](#function-content_property)
- [`properties`](#function-properties)
- [`find_property`](#function-find_property)
- [`register`](#function-register)
- [`register_all`](#function-register_all)
- [`register_table`](#function-register_table)
- [`register_namespaces`](#function-register_namespaces)
- [`find`](#function-find)
- [`find_by_handle`](#function-find_by_handle)
- [`find_by_name`](#function-find_by_name)
- [`registered_types`](#function-registered_types)
- [`is_assignable_from`](#function-is_assignable_from)
- [`is_subclass_of`](#function-is_subclass_of)

<a id="function-new"></a>

### new

```rust
const fn new(name: &'static str, base: Option<&'static TypeInfo>) -> Self
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/type_system.rs#L97)

<a id="function-with_identity"></a>

### with_identity

```rust
const fn with_identity(self: Self, identity: &'static TypeIdentity) -> Self
```

States the identity of the class (`TypeIdentity`): its own static,
which type checks compare. Set by `ferro_class!` for every class.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/type_system.rs#L115)

<a id="function-identity"></a>

### identity

```rust
fn identity(self: &Self) -> Option<&'static TypeIdentity>
```

The identity of the class (`TypeIdentity`), what type checks compare;
`None` for a type that is not a class.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/type_system.rs#L123)

<a id="function-derives_from"></a>

### derives_from

```rust
fn derives_from(self: &Self, identity: &'static TypeIdentity) -> bool
```

Whether this type is the class with the identity `identity` or derives
from it: the type check of `is::<T>()` with `T::IDENTITY`, which, unlike
`is_assignable_from` with `T::TYPE`, does not
keep the initialisation, the constructor and the markup metadata of `T`
in the executable (#612).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/type_system.rs#L133)

<a id="function-with_module_path"></a>

### with_module_path

```rust
const fn with_module_path(self: Self, module_path: &'static str) -> Self
```

States the Rust module that declares the type (`module_path!()` at
the declaration). The markup-facing `namespace` is
derived from it.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/type_system.rs#L147)

<a id="function-with_class_init"></a>

### with_class_init

```rust
const fn with_class_init(self: Self, class_init: fn() -> ()) -> Self
```

Attaches the static initialisation of the type: a function that,
once per thread and after doing the same for the base type, registers
what the type declares (handle casts, property definitions) and runs
its static constructor.

It is what lets code that only has the runtime type (a lookup of a
property by owner type and name) initialise a type that has no
instance yet.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/type_system.rs#L160)

<a id="function-with_constructor"></a>

### with_constructor

```rust
const fn with_constructor(self: Self, constructor: Option<fn() -> Ref<FerroObject>>) -> Self
```

Attaches the default constructor of the class: the function that
creates an instance as its parameterless `new()` does.

The type keeps it only with the tables of types (the feature
`type-tables` of this crate, which the run-time XAML loader, the
designer, DevTools and hot reload enable): those builds create any
class by reflection. Without the feature the constructor is dropped
here, so a runtime type names no constructor and the linker leaves out
the constructor of every class the application never creates (#612,
B3). The decision is made by the features of this crate, wherever the
class is declared: `ferro_class!` passes the constructor to this
function in the crate of the class. Code that names the class creates
it statically (`DefaultConstructible`), or makes its constructor
reachable by reflection with
`register_constructor`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/type_system.rs#L181)

<a id="function-with_handles"></a>

### with_handles

```rust
const fn with_handles(self: Self, handles: fn() -> [TypeId; 2]) -> Self
```

States the Rust types of the handle of the class and of its nullable
form (`Ref<T>`, `Option<Ref<T>>`), which makes the class findable by
the type of a value (`find_by_handle`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/type_system.rs#L197)

<a id="function-with_handle_registration"></a>

### with_handle_registration

```rust
const fn with_handle_registration(self: Self, handle_registration: fn() -> ()) -> Self
```

States the registration of the handle of the class with the untyped
value conversions
(`ValueTypes::register_object`
of the class): what makes `Ref<T>` an object handle and
`Option<Ref<T>>` its nullable form. The initialisation of the class
makes it on the thread that initialises the class; a class of a table
of types (`register_all`) has it on every thread,
initialised or not, because a property of another class may hold the
null of its handle before anything creates an instance of it.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/type_system.rs#L211)

<a id="function-with_interfaces"></a>

### with_interfaces

```rust
const fn with_interfaces(self: Self, interfaces: &'static [TypeOf]) -> Self
```

States the interface handles the class declares
(`ferro_class_info!`, `interfaces`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/type_system.rs#L218)

<a id="function-with_markup"></a>

### with_markup

```rust
const fn with_markup(self: Self, markup: Option<&'static MarkupType>) -> Self
```

Attaches the markup metadata of the class (`ferro_class_info!`,
`markup`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/type_system.rs#L225)

<a id="function-name"></a>

### name

```rust
fn name(self: &Self) -> &'static str
```

The class name, without namespace.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/type_system.rs#L232)

<a id="function-base_type"></a>

### base_type

```rust
fn base_type(self: &Self) -> Option<&'static TypeInfo>
```

The direct base class, if any.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/type_system.rs#L238)

<a id="function-module_path"></a>

### module_path

```rust
fn module_path(self: &Self) -> &'static str
```

The Rust module that declares the type, as `module_path!()` spells
it (`ferroui_base::media::solid_color_brush`). Empty for a type whose
runtime type was written by hand.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/type_system.rs#L246)

<a id="function-namespace"></a>

### namespace

```rust
fn namespace(self: &Self) -> &'static str
```

The dotted, markup-facing namespace of the type (`FerroUI.Media`).

Namespaces are declared once per module, not per class: a crate maps
its module paths to namespaces with `TypeInfo::register_namespaces`
(from its `register_types()` function), and the namespace of a type
is the one registered for the longest prefix of its
`module_path`. Empty when no prefix is
registered.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/type_system.rs#L258)

<a id="function-namespace_of_module"></a>

### namespace_of_module

```rust
fn namespace_of_module(module_path: &str) -> &'static str
```

The dotted namespace registered for a Rust module path; see
`namespace`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/type_system.rs#L265)

<a id="function-full_name"></a>

### full_name

```rust
fn full_name(self: &Self) -> String
```

The namespace-qualified name of the type (`FerroUI.Media.Brush`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/type_system.rs#L270)

<a id="function-ensure_class_init"></a>

### ensure_class_init

```rust
fn ensure_class_init(self: &Self)
```

Ensures the static initialisation of the type and of its base types
has run on the current thread: handle casts and property definitions
are registered (properties in declaration order) and the static
constructors have run, base types first. Does nothing after the first
call on a thread.

Called when the first instance of a class is created, when a property
accessor of the type is first called and by the property registry when
it is asked about the type; call it directly where the static
constructor of a type must have run before none of these happened.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/type_system.rs#L295)

<a id="function-default_constructor"></a>

### default_constructor

```rust
fn default_constructor(self: &Self) -> Option<fn() -> Ref<FerroObject>>
```

The default constructor of the class (see `ferro_class_info!`):
creates an instance as the parameterless `new()` of the class does.

With the tables of types (the feature `type-tables`), the constructor
of every class that declares one. Without them a runtime type names
no constructor (`with_constructor`): this is
the constructor registered for the class with
`register_constructor`, if any, and
`None` otherwise. Code that names the class creates it with
`DefaultConstructible::new_instance` instead.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/type_system.rs#L317)

<a id="function-create_instance"></a>

### create_instance

```rust
fn create_instance(self: &Self) -> Option<Ref<FerroObject>>
```

Creates an instance with the default constructor of the class
(`default_constructor`). `None` if the
class has none (abstract classes, classes that need constructor
arguments, non-instantiable types) and, without the tables of types,
if no constructor is registered for it.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/type_system.rs#L329)

<a id="function-register_constructor"></a>

### register_constructor

```rust
fn register_constructor<T: DefaultConstructible>() -> &'static TypeInfo
```

Makes the default constructor of the class `T` reachable through its
runtime type: after this call, `default_constructor`
and `create_instance` of `T::TYPE` create an
instance of `T`, with or without the tables of types. Returns
`T::TYPE`.

For code that names a class statically and hands its runtime type to
something that creates it by reflection: compiled markup giving
`{x:Type local:Page}` to a frame (`Frame.SourcePageType`,
`Frame.Navigate`), or an application whose view locator creates the
views it registers by name. Only the constructors of the classes named
here are linked (#612, B3). With the tables of types the runtime type
already carries the constructor and nothing is registered.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/type_system.rs#L346)

<a id="function-handle"></a>

### handle

```rust
fn handle(self: &Self) -> Option<TypeId>
```

The Rust type of the handle of the class (`Ref<T>`). `None` for types
that are not classes.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/type_system.rs#L373)

<a id="function-nullable_handle"></a>

### nullable_handle

```rust
fn nullable_handle(self: &Self) -> Option<TypeId>
```

The Rust type of the nullable handle of the class (`Option<Ref<T>>`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/type_system.rs#L378)

<a id="function-interfaces"></a>

### interfaces

```rust
fn interfaces(self: &Self) -> &'static [TypeOf]
```

The interface handles the class itself declares with
`ferro_class_info!` (not the ones of its base classes).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/type_system.rs#L385)

<a id="function-markup"></a>

### markup

```rust
fn markup(self: &Self) -> Option<&'static MarkupType>
```

The markup metadata the class itself declares with
`ferro_class_info!`: its content property, plain properties,
methods, events and attributes. `None` for a class that declares
none; the metadata of its base classes still applies to it.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/type_system.rs#L394)

<a id="function-content_property"></a>

### content_property

```rust
fn content_property(self: &Self) -> Option<&'static str>
```

The name of the content property of the class: the one it declares,
or else the one of the nearest base class that declares one.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/type_system.rs#L400)

<a id="function-properties"></a>

### properties

```rust
fn properties(self: &'static Self) -> Rc<Vec<&'static FerroProperty>>
```

The properties registered on the type and its base types (styled,
direct and the attached properties the type owns), each type's in
declaration order, most derived type first. Initialises the type if
needed, so no instance has to exist.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/type_system.rs#L415)

<a id="function-find_property"></a>

### find_property

```rust
fn find_property(self: &'static Self, name: &str) -> Option<&'static FerroProperty>
```

Finds a property registered on the type or its base types by name.
Initialises the type if needed.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/type_system.rs#L421)

<a id="function-register"></a>

### register

```rust
fn register(type_: &'static TypeInfo)
```

Adds a type to the process-wide table of known types, making it
discoverable with `find` and
`find_by_name`. Registering a type again does
nothing.

Types register themselves when they are initialised on a thread; a
crate's `register_types()` function registers all of its types up
front so that types that were never used are known too.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/type_system.rs#L433)

<a id="function-register_all"></a>

### register_all

```rust
fn register_all(types: &[&'static TypeInfo])
```

Registers several types; see `register`.

The handle of each class is registered with the untyped value
conversions of every thread as well
(`with_handle_registration`), when
the thread next converts an untyped value: the nullable form of the
handle of a class of a table is known whether or not the class has
been initialised. A property typed with the handle of another class
holds its null from the start (`Control.ContextMenu`), and what reads
that value untyped (a binding, markup) must see null. The run-time
XAML loader initialises a class when it reads it, which hid the
difference; compiled markup names a class without initialising it.

Always registers. An application registers its own types with this
function; a crate of the framework registers its table of types with
`register_table`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/type_system.rs#L461)

<a id="function-register_table"></a>

### register_table

```rust
fn register_table(types: &[&'static TypeInfo])
```

Registers the table of types of a crate of the framework, at start-up
from the crate's `register_types()` function; as
`register_all`. Without the feature
`type-tables` the table is trimmed: this does nothing, and what only
the table reaches is left out of the binary. An application registers
its own types with `register_all`, which always
registers.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/type_system.rs#L474)

<a id="function-register_namespaces"></a>

### register_namespaces

```rust
fn register_namespaces(namespaces: &[(&'static str, &'static str)])
```

Declares the namespaces of a crate's modules: pairs of a Rust module
path (`"ferroui_base::media"`) and the dotted namespace of the types
declared in that module and its submodules (`"FerroUI.Media"`). A
longer module path overrides a shorter one, down to a single file.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/type_system.rs#L503)

<a id="function-find"></a>

### find

```rust
fn find(namespace: &str, name: &str) -> Option<&'static TypeInfo>
```

Finds a known type by namespace and name.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/type_system.rs#L544)

<a id="function-find_by_handle"></a>

### find_by_handle

```rust
fn find_by_handle(handle: TypeId) -> Option<(&'static TypeInfo, bool)>
```

Finds the known class whose handle (`Ref<T>`) or nullable handle
(`Option<Ref<T>>`) is the Rust type `handle`. The flag tells whether
it is the nullable handle.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/type_system.rs#L553)

<a id="function-find_by_name"></a>

### find_by_name

```rust
fn find_by_name(name: &str) -> Option<&'static TypeInfo>
```

Finds a known type by name alone. `None` if no type or more than one
type (in different namespaces) has the name.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/type_system.rs#L559)

<a id="function-registered_types"></a>

### registered_types

```rust
fn registered_types() -> Vec<&'static TypeInfo>
```

Every known type, in registration order.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/type_system.rs#L568)

<a id="function-is_assignable_from"></a>

### is_assignable_from

```rust
fn is_assignable_from(self: &Self, other: &TypeInfo) -> bool
```

Returns true if `other` is this type or derives from it.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/type_system.rs#L573)

<a id="function-is_subclass_of"></a>

### is_subclass_of

```rust
fn is_subclass_of(self: &Self, other: &TypeInfo) -> bool
```

Returns true if this type is `other` or derives from it.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/type_system.rs#L586)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- [`ResourceKeyObject`](/docs/0.5.0/api/ferroui-base/controls/trait-resourcekeyobject/)
- [`AnyValue`](/docs/0.5.0/api/ferroui-base/trait-anyvalue/)
- [`ClassDefaults`](/docs/0.5.0/api/ferroui-base/trait-classdefaults/)
- `Borrow<T>`
- `BorrowMut<T>`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- `ToString`
- `ErasedDestructor`
- `IntoEither`
- `From<&'static TypeInfo>`
- [`MarkupTyped`](/docs/0.5.0/api/ferroui-base/metadata/trait-markuptyped/)
- `PartialEq`
- `Eq`
- `Hash`
- `Debug`
- `Display`

## Availability

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