rok::core::reflect
rok::core::reflect - Reflect / Inspect (refs-lang 6.10, stdlib 2.12).
Reflect is implemented by the compiler for every type (no impl in
source; a manual one is an error): T::type_name(), T::size(),
T::align() are constants, and x.type_name_of() / x.size_of() look
at the variant an any or sum value holds at run time. A type's own
method of the same name wins.
Inspect is opt-in through #[derive(Inspect)], written below as a
meta block (6.10.2): field names, dynamic field get / set through
any, and the type's inherent methods.
Structs
MethodInfo
pub struct MethodInfoOne inherent method of an Inspect type. 6.10 names name / arity /
is_static, 2.12 name / arg_types / return_type: both are here.
arity and arg_types leave out self.
pub name: strpub arity: usizepub is_static: boolpub arg_types: List<str>pub return_type: str
Traits
Reflect
pub trait Reflectfn type_name() -> strfn size() -> usizefn align() -> usizefn type_name_of(self) -> strfn size_of(self) -> usize
Inspect
pub trait Inspect: Reflectfn field_names() -> List<str>fn get_field(self, name: str) -> any | nonefn set_field(ref self, name: str, value: any) -> boolfn methods() -> List<MethodInfo>
Functions
cast
pub fn cast<T>(value: any) -> T | nonevalue as a T: the value when it holds a T; an integer of another
integer type when it fits in T (set_field("id", 42) on a u64
field); else none.
methods_of
pub const fn methods_of<T>() -> List<MethodInfo>T's inherent methods, by name.