module aptos_std::type_info { use std::string; struct TypeInfo has copy, drop, store { account_address: address, module_name: vector, struct_name: vector, } public fun account_address(type_info: &TypeInfo): address { type_info.account_address } public fun module_name(type_info: &TypeInfo): vector { type_info.module_name } public fun struct_name(type_info: &TypeInfo): vector { type_info.struct_name } public native fun type_of(): TypeInfo; public native fun type_name(): string::String; spec type_of { // TODO: temporary mockup. pragma opaque; } #[test] fun test() { let type_info = type_of(); assert!(account_address(&type_info) == @aptos_std, 0); assert!(module_name(&type_info) == b"type_info", 1); assert!(struct_name(&type_info) == b"TypeInfo", 2); } #[test] fun test_type_name() { use aptos_std::table::Table; assert!(type_name() == string::utf8(b"bool"), 0); assert!(type_name() == string::utf8(b"u8"), 1); assert!(type_name() == string::utf8(b"u64"), 2); assert!(type_name() == string::utf8(b"u128"), 3); assert!(type_name
() == string::utf8(b"address"), 4); assert!(type_name() == string::utf8(b"signer"), 5); // vector assert!(type_name>() == string::utf8(b"vector"), 6); assert!(type_name>>() == string::utf8(b"vector>"), 7); assert!(type_name>>() == string::utf8(b"vector>"), 8); // struct assert!(type_name() == string::utf8(b"0x1::type_info::TypeInfo"), 9); assert!(type_name< Table< TypeInfo, Table> > >() == string::utf8(b"0x1::table::Table<0x1::type_info::TypeInfo, 0x1::table::Table>>"), 10); } }