Dynamic Typing
This extension defines an opaque type Any
for representing values of unknown type:
any.sidex
/// A value of unknown type.
opaque AnyData
opaque TypeId
record Any {
type_id: TypeId,
data: AnyData,
}
Imagine you like to define an RPC protocol with Sidex where arguments and return values of remote procedure calls can, from the perspective of the protocol, be any value. This is where Any
is useful.
To use AnyV
in your schemas, you have to explicitly import it:
import ::std::any::Any
As with any extension, backends and format mappings may or may not support Any
.
For JSON and the Rust backend, the following attributes on Any
are implicit:
#[json(type = "any")]
#[rust(type = "::sidex::any::Any")]
As a result, it also works with the TypeScript backend out-of-the-box.