FerroUI/ docs

Search guides, controls, Rust APIs, and XAML.

    GitHub ↗

    TypeInfo

    struct · ferroui-base · v0.5.0

    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

    Members

    new

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

    Source

    with_identity

    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

    identity

    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

    derives_from

    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

    with_module_path

    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

    with_class_init

    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

    with_constructor

    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

    with_handles

    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

    with_handle_registration

    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

    with_interfaces

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

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

    Source

    with_markup

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

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

    Source

    name

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

    The class name, without namespace.

    Source

    base_type

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

    The direct base class, if any.

    Source

    module_path

    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

    namespace

    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

    namespace_of_module

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

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

    Source

    full_name

    fn full_name(self: &Self) -> String
    

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

    Source

    ensure_class_init

    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

    default_constructor

    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

    create_instance

    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

    register_constructor

    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

    handle

    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

    nullable_handle

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

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

    Source

    interfaces

    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

    markup

    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

    content_property

    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

    properties

    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

    find_property

    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

    register

    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

    register_all

    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

    register_table

    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

    register_namespaces

    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

    find

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

    Finds a known type by namespace and name.

    Source

    find_by_handle

    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

    find_by_name

    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

    registered_types

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

    Every known type, in registration order.

    Source

    is_assignable_from

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

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

    Source

    is_subclass_of

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

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

    Source

    Trait implementations

    • Send
    • Sync
    • Freeze
    • UnsafeUnpin
    • Unpin
    • UnwindSafe
    • RefUnwindSafe
    • ResourceKeyObject
    • AnyValue
    • ClassDefaults
    • Borrow<T>
    • BorrowMut<T>
    • Into<U>
    • From<T>
    • TryInto<U>
    • TryFrom<U>
    • Any
    • ToString
    • ErasedDestructor
    • IntoEither
    • From<&'static TypeInfo>
    • MarkupTyped
    • PartialEq
    • Eq
    • Hash
    • Debug
    • Display

    Availability

    Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.