Type-safe Any for WASM/JS/Native targets, without json/string serialization

///|
test "Any and dyn_cast" {
let a : @any.Any = Any(false)
let b : @any.Any = Any([1, 2, 3])
let c : Bool = a.dyn_cast()
let d : Array[Int] = b.dyn_cast()
let e : Result[Int, _] = try! b.dyn_cast()
debug_inspect(c, content="false")
debug_inspect(d, content="[1, 2, 3]")
debug_inspect(
e,
content=(
#|Err(Failure("failed to cast Array[Int] to Int"))
),
)
}///|
test "dyn_cast failed" {
let a = Any(false)
debug_inspect(
try! (a.dyn_cast() : Int),
content=(
#|Err(Failure("README.mbt.md:50:13-50:25@Yoorkin/any FAILED: failed to cast Bool to Int"))
),
)
}///|
struct Pos {
x : Int
y : Int
} derive(Debug)
///|
@any.Payload {
Pos(Pos)
}
///|
impl Anyable for Pos with fn iso() {
{
id: TypeId("my/pkg", "Pos", []),
box: p => Pos(p),
unbox: payload => {
guard payload is Pos(p)
p
},
}
}
///|
test {
let a = Any({ x: 10, y: 20 })
let b : Pos = a.dyn_cast()
debug_inspect(b, content="{ x: 10, y: 20 }")
}impl Anyable for FlagActionimpl Anyable for OptionActionimpl Anyable for PositionArgimpl Anyable for ValueRangeimpl Anyable for ValueSourceimpl Anyable for PriorityQueue[T]impl Anyable for JsonDecodeErrorimpl Anyable for ParseErrorimpl Anyable for PriorityQueue[T]impl Anyable for RandomStateimpl Anyable for MatchResultimpl Anyable for StringViewtype AnyType-safe Any for WASM/JS/Native targets, without json/string serialization