Skip to content

Latest commit

 

History

History
102 lines (51 loc) · 2.3 KB

any.md

File metadata and controls

102 lines (51 loc) · 2.3 KB

Module 0x2::any

Struct Any

A type which can represent a value of any type. This allows for representation of 'unknown' future values. For example, to define a resource such that it can be later be extended without breaking changes one can do

struct Resource {
field: Type,
...
extension: Option<Any>
}
struct Any has drop, store

Constants

const ErrorInvalidBytes: u64 = 2;

The type provided for unpack is not the same as was given for pack.

const ErrorTypeMismatch: u64 = 1;

Function pack

Pack a value into the Any representation. Because Any can be stored and dropped, this is also required from T.

public fun pack<T: drop, store>(x: T): any::Any

Function unpack

Unpack a value from the Any representation. This aborts if the value has not the expected type T.

public fun unpack<T>(x: any::Any): T

Function type_name

Returns the type name of this Any

public fun type_name(x: &any::Any): &string::String