Module reflection
Intrinsics for compile time reflection
This are all methods operating on TypeId which is the
entry point to all compile time reflection.
Functions
- type_id Gets an identifier which is globally unique to the specified type. This function will return the same value for a type regardless of whichever crate it is invoked in.
-
type_id_array_len
Gets the length of the array represented by this
TypeId. -
type_id_element_ty
Gets the type of each element of the array or slice represented by this
TypeId. -
type_id_eq
Tests (at compile-time) if two
crate::any::TypeIdinstances identify the same type. This is necessary because at const-eval time the actual discriminating data is opaque and cannot be inspected directly. -
type_id_field_representing_type
Gets the
FieldRepresentingType'sTypeIdat the given index of the type represented by thisTypeId. -
type_id_fields
Gets the number of fields at the given
variant_indexrepresented by thisTypeId. -
type_id_function_ptr
Given a
TypeIdthat represents a function pointer returns ancore::mem::type_info::FnPtr. When called on something else this returnsNone. - type_id_generics Returns the list of generic args on this type. Only meaningful for Adts, closures, ... Everything else returns an empty slice.
-
type_id_is_signed
Returns whether the type represented by this
TypeIdis a signed integer. - type_id_non_exhaustive Checks whether this type is non-exhaustive.
-
type_id_points_mutably
Given a
TypeIdthat represents a pointer returns whether that pointer is mutable. When called on anything else this returnsfalse. -
type_id_points_to
Given a
TypeIdthat represents a pointer this returns theTypeIdwhich that pointer points to. When called on anything else this returns None. -
type_id_size_of
Gets the size of the type represented by this
TypeId. - type_id_type_of Compute the type information of a concrete type. It can only be called at compile time, the backends do not implement it.
-
type_id_variant_name
Gets the name of the variant represented by the base
TypeIdand variant_idx. -
type_id_variant_non_exhaustive
Returns true when the variant represented by the base
TypeIdand variant_idx is non exhaustive. -
type_id_variants
Gets the number of variants of the type represented by this
TypeId. -
type_id_vtable
Check if a type represented by a
TypeIdimplements a trait represented by aTypeId. It can only be called at compile time, the backends do not implement it. If it implements the trait the dyn metadata gets returned for vtable access. - type_name Gets a static string slice containing the name of a type.