Skip to contents

A child holds its ancestors' fields first, so the value of an ancestor is those fields with the ancestor's type. The fields are the child's own objects, not copies, and a Rust-stored ancestor's codec builds its state from them. The result is valid: the child's rules include the ancestor's, which read the ancestor's fields only. r8convert(x, Parent) returns the same value, and an impl of the ancestor in compiled code receives it.

Usage

r8upcast(x, type)

Arguments

x

A value of a struct with extends.

type

An R8 struct type object: x's type or one of its ancestors.

Value

A value of type; x itself when type is its 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)
r8upcast(Window(lo = 1, hi = 2, label = "w"), Range)
#> <demo::Range>
#>   lo: 1
#>   hi: 2
options(op)