Skip to contents

A sum type of unit, struct, and newtype variants. An enum of unit variants is written as the variant name; an enum with another variant as an object whose tag member names the variant. Kernel@Linear is a unit variant's value. An exported enum changes as an exported struct does: see the section "Changing a type that other packages use" of new_struct().

Usage

new_enum(
  name,
  variants = list(),
  description = "",
  tag = "type",
  version = 1L,
  storage = c("r", "rust")
)

# S3 method for class 'r8_enum_type'
object@name

Arguments

name

The variant's name.

variants

Named list: The variants, variant() calls.

description

Character: What the type is.

tag

Character: The member of an object variant's JSON form that holds the variant's name. A trait's tag is another member, which holds an implementor's type.

version

Integer: The type's version, from 1.

storage

Character {"r", "rust"}: Where values hold their fields. "rust": a Rust-stored type, whose values, unit variants included, the codec in the package's compiled exports builds and holds. Its variant constructors and unit variants signal r8_codec_missing_error until the codec is registered.

object

An enum type object.

Value

new_enum(): the type object, of class r8_enum_type. Kernel@Linear: the unit variant's value, an R8 value.

Examples

op <- options(r8.namespace = "demo")
Kernel <- new_enum("Kernel", variants = list(
  Linear = variant(),
  Rbf = variant(fields = list(gamma = type_double(exclusive_min = 0)))
))
Kernel@Linear
#> <demo::Kernel@Linear>
options(op)