0x1::TypeInfo
TypeInfo
account_address
module_name
struct_name
type_of
size_of_val
use 0x1::BCS;
use 0x1::Token;
TypeInfo
struct TypeInfo has copy, drop, store
account_address: address
module_name: vector<u8>
struct_name: vector<u8>
account_address
public fun account_address(type_info: &TypeInfo::TypeInfo): address
public fun account_address(type_info: &TypeInfo): address {
type_info.account_address
}
module_name
public fun module_name(type_info: &TypeInfo::TypeInfo): vector<u8>
public fun module_name(type_info: &TypeInfo): vector<u8> {
*&type_info.module_name
}
struct_name
public fun struct_name(type_info: &TypeInfo::TypeInfo): vector<u8>
public fun struct_name(type_info: &TypeInfo): vector<u8> {
*&type_info.struct_name
}
type_of
public fun type_of<T>(): TypeInfo::TypeInfo
public fun type_of<T>(): TypeInfo {
let (account_address, module_name, struct_name) = Token::type_of<T>();
TypeInfo {
account_address,
module_name,
struct_name
}
}
size_of_val
Return the BCS size, in bytes, of value at val_ref
.
See the BCS spec
See test_size_of_val()
for an analysis of common types and
nesting patterns, as well as test_size_of_val_vectors()
for an
analysis of vector size dynamism.
public fun size_of_val<T: store>(val_ref: &T): u64
public fun size_of_val<T: store>(val_ref: &T): u64 {
// Return vector length of vectorized BCS representation.
Vector::length(&BCS::to_bytes<T>(val_ref))
}