Skip to main content

TypeInfo

Struct TypeInfo 

Source
pub struct TypeInfo { /* private fields */ }
Expand description

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!].

Implementations§

Source§

impl TypeInfo

Source

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

Source

pub const fn with_module_path(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

pub const fn with_class_init(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

pub const fn with_constructor( 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.

Source

pub const fn with_handles(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

pub const fn with_handle_registration(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

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

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

Source

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

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

Source

pub fn name(&self) -> &'static str

The class name, without namespace.

Source

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

The direct base class, if any.

Source

pub fn module_path(&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

pub fn namespace(&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

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

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

Source

pub fn full_name(&self) -> String

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

Source

pub fn ensure_class_init(&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

pub fn default_constructor(&self) -> Option<fn() -> Ref<FerroObject>>

The default constructor of the class, if it declares one (see [ferro_class_info!]): creates an instance as the parameterless new() of the class does.

Source

pub fn create_instance(&self) -> Option<Ref<FerroObject>>

Creates an instance with the default constructor of the class. None if the class has none (abstract classes, classes that need constructor arguments, non-instantiable types).

Source

pub fn handle(&self) -> Option<TypeId>

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

Source

pub fn nullable_handle(&self) -> Option<TypeId>

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

Source

pub fn interfaces(&self) -> &'static [TypeOf] ⓘ

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

Source

pub fn markup(&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

pub fn content_property(&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

pub fn properties(&'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

pub fn find_property( &'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

pub 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

pub 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.

Source

pub 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

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

Finds a known type by namespace and name.

Source

pub 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

pub 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

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

Every known type, in registration order.

Source

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

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

Source

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

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

Trait Implementations§

Source§

impl Debug for TypeInfo

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for TypeInfo

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for TypeInfo

Source§

impl From<&'static TypeInfo> for ResourceKey

Source§

fn from(value: &'static TypeInfo) -> Self

Converts to this type from the input type.
Source§

impl Hash for TypeInfo

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl MarkupTyped for TypeInfo

Source§

const MARKUP: &'static MarkupType

The markup metadata of the type.
Source§

impl PartialEq for TypeInfo

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AnyValue for T
where T: PartialEq + 'static,

Source§

fn any_value_as_any(&self) -> &(dyn Any + 'static)

Source§

fn any_value_eq(&self, other: &(dyn AnyValue + 'static)) -> bool

Source§

fn any_value_type_name(&self) -> &'static str

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ClassDefaults for T
where T: ?Sized,

Source§

fn static_constructor()

The static constructor of a type: work done once per thread, after the properties of the type are registered and before its first instance exists (class handlers, affects_render, metadata overrides). Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ResourceKeyObject for T
where T: Eq + Hash + 'static,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

fn dyn_eq(&self, other: &(dyn ResourceKeyObject + 'static)) -> bool

Source§

fn dyn_hash(&self, state: &mut dyn Hasher)

Source§

fn key_type_name(&self) -> &'static str

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.