xur_

> module

std::any

runtime type information

use std::any; in the browser

std::any names the types of values at runtime, converts structs to records, and checks a value against a struct type.

> functions

# record(value: any) -> record

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.

# try_cast(value: any) -> Result<T, str>

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.

# type_name() -> str

Returns the name of the type argument, called as any::type_name::<i64>(). Without exactly one type argument it is a runtime error.

# type_name_val(value: any) -> str

Returns the name of value's runtime type.

# type_of(value: any) -> type

Returns 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));
}