rokdocs
v0.1

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 MethodInfo

One 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: str
  • pub arity: usize
  • pub is_static: bool
  • pub arg_types: List<str>
  • pub return_type: str

Traits

Reflect

pub trait Reflect
  • fn type_name() -> str
  • fn size() -> usize
  • fn align() -> usize
  • fn type_name_of(self) -> str
  • fn size_of(self) -> usize

Inspect

pub trait Inspect: Reflect
  • fn field_names() -> List<str>
  • fn get_field(self, name: str) -> any | none
  • fn set_field(ref self, name: str, value: any) -> bool
  • fn methods() -> List<MethodInfo>

Functions

cast

pub fn cast<T>(value: any) -> T | none

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