> module
std::any
runtime type information
std::any names the types of values at runtime, converts structs to records, and checks a value against a struct type.
> functions
Converts a struct into an untyped record with the same fields (tuple fields are named 0, 1, ...). A record is returned unchanged; anything else is a runtime error.
Called as any::try_cast::<T>(value), where T is a struct type. Returns Ok with value coerced to T, or Err with the reason it doesn't fit.
Returns the name of the type argument, called as any::type_name::<i64>(). Without exactly one type argument it is a runtime error.
type_of(value: any) -> typeReturns value's runtime type as a type value, preserving integer and float width (so the type of a u8 byte is u8, not i64). Compare it against a type literal (e.g. u8, f32)toassertavalue'sexacttype.
> examples
use std::any;
use std::assert;
use std::io;
fn main() {
io::println("{}", any::type_name::<i64>());
io::println("{}", any::type_of(42)); // i64
// Byte indexing yields a u8; assert the type directly.
let byte = b"\xff"[0];
assert::is_eq(u8, any::type_of(byte));
}