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
impl TypeInfo
pub const fn new(name: &'static str, base: Option<&'static TypeInfo>) -> Self
Sourcepub const fn with_module_path(self, module_path: &'static str) -> Self
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.
Sourcepub const fn with_class_init(self, class_init: fn()) -> Self
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.
Sourcepub const fn with_constructor(
self,
constructor: Option<fn() -> Ref<FerroObject>>,
) -> Self
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.
Sourcepub const fn with_handles(self, handles: fn() -> [TypeId; 2]) -> Self
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).
Sourcepub const fn with_handle_registration(self, handle_registration: fn()) -> Self
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.
Sourcepub const fn with_interfaces(self, interfaces: &'static [TypeOf]) -> Self
pub const fn with_interfaces(self, interfaces: &'static [TypeOf]) -> Self
States the interface handles the class declares
([ferro_class_info!], interfaces).
Sourcepub const fn with_markup(self, markup: Option<&'static MarkupType>) -> Self
pub const fn with_markup(self, markup: Option<&'static MarkupType>) -> Self
Attaches the markup metadata of the class ([ferro_class_info!],
markup).
Sourcepub fn module_path(&self) -> &'static str
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.
Sourcepub fn namespace(&self) -> &'static str
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.
Sourcepub fn namespace_of_module(module_path: &str) -> &'static str
pub fn namespace_of_module(module_path: &str) -> &'static str
The dotted namespace registered for a Rust module path; see
namespace.
Sourcepub fn full_name(&self) -> String
pub fn full_name(&self) -> String
The namespace-qualified name of the type (FerroUI.Media.Brush).
Sourcepub fn ensure_class_init(&self)
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.
Sourcepub fn default_constructor(&self) -> Option<fn() -> Ref<FerroObject>>
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.
Sourcepub fn create_instance(&self) -> Option<Ref<FerroObject>>
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).
Sourcepub fn handle(&self) -> Option<TypeId>
pub fn handle(&self) -> Option<TypeId>
The Rust type of the handle of the class (Ref<T>). None for types
that are not classes.
Sourcepub fn nullable_handle(&self) -> Option<TypeId>
pub fn nullable_handle(&self) -> Option<TypeId>
The Rust type of the nullable handle of the class (Option<Ref<T>>).
Sourcepub fn interfaces(&self) -> &'static [TypeOf] ⓘ
pub fn interfaces(&self) -> &'static [TypeOf] ⓘ
The interface handles the class itself declares with
[ferro_class_info!] (not the ones of its base classes).
Sourcepub fn markup(&self) -> Option<&'static MarkupType>
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.
Sourcepub fn content_property(&self) -> Option<&'static str>
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.
Sourcepub fn properties(&'static self) -> Rc<Vec<&'static FerroProperty>>
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.
Sourcepub fn find_property(
&'static self,
name: &str,
) -> Option<&'static FerroProperty>
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.
Sourcepub fn register(type_: &'static TypeInfo)
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.
Sourcepub fn register_all(types: &[&'static TypeInfo])
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.
Sourcepub fn register_namespaces(namespaces: &[(&'static str, &'static str)])
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.
Sourcepub fn find(namespace: &str, name: &str) -> Option<&'static TypeInfo>
pub fn find(namespace: &str, name: &str) -> Option<&'static TypeInfo>
Finds a known type by namespace and name.
Sourcepub fn find_by_handle(handle: TypeId) -> Option<(&'static TypeInfo, bool)>
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.
Sourcepub fn find_by_name(name: &str) -> Option<&'static TypeInfo>
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.
Sourcepub fn registered_types() -> Vec<&'static TypeInfo>
pub fn registered_types() -> Vec<&'static TypeInfo>
Every known type, in registration order.
Sourcepub fn is_assignable_from(&self, other: &TypeInfo) -> bool
pub fn is_assignable_from(&self, other: &TypeInfo) -> bool
Returns true if other is this type or derives from it.
Sourcepub fn is_subclass_of(&self, other: &TypeInfo) -> bool
pub fn is_subclass_of(&self, other: &TypeInfo) -> bool
Returns true if this type is other or derives from it.
Trait Implementations§
impl Eq for TypeInfo
Source§impl From<&'static TypeInfo> for ResourceKey
impl From<&'static TypeInfo> for ResourceKey
Source§impl MarkupTyped for TypeInfo
impl MarkupTyped for TypeInfo
Source§const MARKUP: &'static MarkupType
const MARKUP: &'static MarkupType
Auto Trait Implementations§
impl Freeze for TypeInfo
impl RefUnwindSafe for TypeInfo
impl Send for TypeInfo
impl Sync for TypeInfo
impl Unpin for TypeInfo
impl UnsafeUnpin for TypeInfo
impl UnwindSafe for TypeInfo
Blanket Implementations§
Source§impl<T> AnyValue for Twhere
T: PartialEq + 'static,
impl<T> AnyValue for Twhere
T: PartialEq + 'static,
fn any_value_as_any(&self) -> &(dyn Any + 'static)
fn any_value_eq(&self, other: &(dyn AnyValue + 'static)) -> bool
fn any_value_type_name(&self) -> &'static str
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> ClassDefaults for Twhere
T: ?Sized,
impl<T> ClassDefaults for Twhere
T: ?Sized,
Source§fn static_constructor()
fn static_constructor()
affects_render, metadata
overrides). Read more