core::reflect::info
本頁內容
API 參考只有英文版,由標準函式庫原始碼中的英文文件註解產生。
TypeInfo, a type's description.
The compiler emits a descriptor in read-only data for every type a
program asks about (info::<T>(), T::type_info()) and for the
types it is made of. A TypeInfo is the descriptor's address; its
accessors read it in place and allocate nothing, except those that
return a List.
Structs
ReflectErrorSource
pub struct ReflectErrorAn error of TypeInfo::build and the container conversions: what is
wrong, in words.
Trait implementations 2
impl Display for ReflectErrorimpl Error for ReflectError
TypeInfoSource
pub struct TypeInfoA type's description. Two are equal when they describe the same type, even from different modules.
The description at
at, the address of a type descriptor that stays mapped while it is used (std::plugin::Plugin::types).The name
Reflect::type_namegives:Player,List<f64>.The full path:
game::Player; empty for a type without one.The package the type is defined in: the path's first part.
The key that names the type across modules:
Y3f8a1c2b:game::Player.A hash of the type's layout: equal for equal layouts.
What kind of type it is.
Size in bytes, as
T::size().Alignment in bytes, as
T::align().Whether
#[derive(Inspect)]describes its fields and gives access to them.The fields, in declaration order (
#[inspect(skip)]ones left out). Empty for an enum: its fields are its variants'.How many fields
fields()lists.Field
i(i < field_count()).The field named
name.The field named
nameofvalue: of the variant it holds for an enum.An enum's variants, in declaration order.
How many variants an enum has.
Variant
i(i < variant_count()).The variant named
name.The variant an enum
valueholds;nonefor another type.The types it is made of: an instance's type arguments, a sum's members, a tuple's parts, a list's element, a dict's key and value.
How many types
generics()lists.Type
iofgenerics().The element of a list or array, the value of a dict.
The key of a dict.
The runtime attribute
Aon the type, if it has one.The runtime attributes on the type.
Whether
valueholds this type.A value with every field at its default, or
nonewhen a field has none.
Sourcepub fn build(§self, fields: Dict<str, any>) throws (ReflectError) -> any A struct from named fields; a missing field takes its default.
The length of a list
value; 0 for another type.Item
iof a listvalue.The items of a list
value;nonefor another type.
Sourcepub fn list_from(§self, items: List<any>) throws (ReflectError) -> any A list of this type from
items.The entries of a dict
value;nonefor another type.
Sourcepub fn dict_from(§self, items: List<(any, any)>) throws (ReflectError) -> any A dict of this type from
items.
TypeRefSource
pub struct TypeRefA reference to a type by name, with its description when there is one.
The type's name, as
TypeInfo::name.Its description.
VariantSource
pub struct VariantOne variant of an enum.
The variant's name.
Its position in declaration order.
The variant's fields, in declaration order.
How many fields the variant has.
Field
i(i < field_count()).The variant's field named
name.The runtime attribute
Aon the variant, if it has one.The runtime attributes on the variant.
Sourcepub fn build(§self, fields: Dict<str, any>) throws (ReflectError) -> any A value of this variant from named fields.
Enums
TypeKindSource
pub enum TypeKindWhat kind of type a TypeInfo describes.
Functions
infoSource
pub fn info<T>() -> TypeInfo T's description; its fields and accessors when T is Inspect.
info_ofSource
pub fn info_of(value: any) -> TypeInfo | none The description of the type value holds, when the program has one
(the type, or a type made of it, is asked about somewhere).
findSource
pub fn find(path: str) -> TypeInfo | none The description of the type at path ("game::Player"), when the
program has one.