Skip to contents

subtype(Struct) holds a value of Struct or of a struct that extends a subtype of it: a type is a subtype of itself and of every ancestor through extends. Such a value has the struct's fields and satisfies its rules, and r8upcast() gives its value of Struct. A plain struct type holds exactly that struct. Its JSON form names the value's type in "$type". Any implementor of a trait, related by extends or not, is dyn().

Usage

subtype(struct)

Arguments

struct

An R8 struct type object.

Value

An r8_field_type.

Examples

op <- options(r8.namespace = "demo")
Range <- new_struct("Range", fields = list(lo = type_double(), hi = type_double()))
Window <- new_struct("Window", fields = list(label = type_character()), extends = Range)
Plot <- new_struct("Plot", fields = list(x = subtype(Range)))
Plot(x = Window(lo = 0, hi = 1, label = "w"))
#> <demo::Plot>
#>   x: <demo::Window>
#>     lo: 0
#>     hi: 1
#>     label: "w"
options(op)