docs

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 ReflectError

An error of TypeInfo::build and the container conversions: what is wrong, in words.

Trait implementations 2
  • impl Display for ReflectError
  • impl Error for ReflectError

TypeInfoSource

pub struct TypeInfo

A type's description. Two are equal when they describe the same type, even from different modules.

  • pub unsafe fn from_desc(at: usize) -> TypeInfo§

    Source

    The description at at, the address of a type descriptor that stays mapped while it is used (std::plugin::Plugin::types).

  • pub fn name(self) -> str§

    Source

    The name Reflect::type_name gives: Player, List<f64>.

  • pub fn path(self) -> str§

    Source

    The full path: game::Player; empty for a type without one.

  • pub fn package(self) -> str§

    Source

    The package the type is defined in: the path's first part.

  • pub fn type_key(self) -> str§

    Source

    The key that names the type across modules: Y3f8a1c2b:game::Player.

  • pub fn layout_hash(self) -> u64§

    Source

    A hash of the type's layout: equal for equal layouts.

  • pub fn kind(self) -> TypeKind§

    Source

    What kind of type it is.

  • pub fn size(self) -> usize§

    Source

    Size in bytes, as T::size().

  • pub fn align(self) -> usize§

    Source

    Alignment in bytes, as T::align().

  • pub fn is_inspect(self) -> bool§

    Source

    Whether #[derive(Inspect)] describes its fields and gives access to them.

  • pub fn fields(self) -> List<Field>§

    Source

    The fields, in declaration order (#[inspect(skip)] ones left out). Empty for an enum: its fields are its variants'.

  • pub fn field_count(self) -> usize§

    Source

    How many fields fields() lists.

  • pub fn field_at(self, i: usize) -> Field§

    Source

    Field i (i < field_count()).

  • pub fn field(self, name: str) -> Field | none§

    Source

    The field named name.

  • pub fn field_of_val(self, value: any, name: str) -> Field | none§

    Source

    The field named name of value: of the variant it holds for an enum.

  • pub fn variants(self) -> List<Variant>§

    Source

    An enum's variants, in declaration order.

  • pub fn variant_count(self) -> usize§

    Source

    How many variants an enum has.

  • pub fn variant_at(self, i: usize) -> Variant§

    Source

    Variant i (i < variant_count()).

  • pub fn variant(self, name: str) -> Variant | none§

    Source

    The variant named name.

  • pub fn variant_of(self, value: any) -> Variant | none§

    Source

    The variant an enum value holds; none for another type.

  • pub fn generics(self) -> List<TypeRef>§

    Source

    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.

  • pub fn generic_count(self) -> usize§

    Source

    How many types generics() lists.

  • pub fn generic_at(self, i: usize) -> TypeRef§

    Source

    Type i of generics().

  • pub fn element(self) -> TypeRef | none§

    Source

    The element of a list or array, the value of a dict.

  • pub fn key(self) -> TypeRef | none§

    Source

    The key of a dict.

  • pub fn attr<A>(self) -> A | none§

    Source

    The runtime attribute A on the type, if it has one.

  • pub fn attrs(self) -> List<Attr>§

    Source

    The runtime attributes on the type.

  • pub fn holds(self, value: any) -> bool§

    Source

    Whether value holds this type.

  • pub fn new_default(self) -> any | none§

    Source

    A value with every field at its default, or none when a field has none.

  • pub fn build(self, fields: Dict<str, any>) throws (ReflectError) -> any§

    Source

    A struct from named fields; a missing field takes its default.

  • pub fn list_len(self, value: any) -> usize§

    Source

    The length of a list value; 0 for another type.

  • pub fn list_get(self, value: any, i: usize) -> any | none§

    Source

    Item i of a list value.

  • pub fn list_items(self, value: any) -> List<any> | none§

    Source

    The items of a list value; none for another type.

  • pub fn list_from(self, items: List<any>) throws (ReflectError) -> any§

    Source

    A list of this type from items.

  • pub fn dict_items(self, value: any) -> List<(any, any)> | none§

    Source

    The entries of a dict value; none for another type.

  • pub fn dict_from(self, items: List<(any, any)>) throws (ReflectError) -> any§

    Source

    A dict of this type from items.

Trait implementations 3

TypeRefSource

pub struct TypeRef

A reference to a type by name, with its description when there is one.

  • pub fn name(self) -> str§

    Source

    The type's name, as TypeInfo::name.

  • pub fn info(self) -> TypeInfo | none§

    Source

    Its description.

Trait implementations 2

VariantSource

pub struct Variant

One variant of an enum.

  • pub fn name(self) -> str§

    Source

    The variant's name.

  • pub fn index(self) -> usize§

    Source

    Its position in declaration order.

  • pub fn fields(self) -> List<Field>§

    Source

    The variant's fields, in declaration order.

  • pub fn field_count(self) -> usize§

    Source

    How many fields the variant has.

  • pub fn field_at(self, i: usize) -> Field§

    Source

    Field i (i < field_count()).

  • pub fn field(self, name: str) -> Field | none§

    Source

    The variant's field named name.

  • pub fn attr<A>(self) -> A | none§

    Source

    The runtime attribute A on the variant, if it has one.

  • pub fn attrs(self) -> List<Attr>§

    Source

    The runtime attributes on the variant.

  • pub fn build(self, fields: Dict<str, any>) throws (ReflectError) -> any§

    Source

    A value of this variant from named fields.

Trait implementations 2

Enums

TypeKindSource

pub enum TypeKind

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