dyn(Trait) holds a value of any R8 type that implements Trait, or
that extends a type that does, as Rust's dyn Trait. Its JSON form names
the type in the trait's tag member, or else in "$type". dyn(generic),
for a generic from generic() that dispatches on one argument, holds a
value of any type with a method of the generic. A value of a class of
another class system is not held, even when the class has an impl of the
trait; r8convert() through a From impl turns it into an R8 value. A
struct and the structs that extend it are subtype().
Arguments
- trait
A trait object from
new_trait(), or a generic fromgeneric()that dispatches on one argument.
Examples
op <- options(r8.namespace = "demo")
Planar <- new_trait("Planar", methods = list(area = trait_method(params(x))))
Square <- new_struct("Square", fields = list(side = type_double()))
impl(Planar, Square, methods = list(area = function(x) x$side^2))
Drawing <- new_struct("Drawing", fields = list(shape = dyn(Planar)))
Drawing(shape = Square(side = 2))#> <demo::Drawing>
#> shape: <demo::Square>
#> side: 2options(op)