Skip to contents

The list-shaped counterpart of the constructor: unknown keys are ignored unless the struct was declared with .extra = "forbid", and nested lists are parsed into nested structs.

Usage

from_list(struct, x)

Arguments

struct

A struct, or anything as_type() accepts.

x

A named list.

Value

An instance.

Examples

Msg <- struct("Msg", topic = chr[1], size = int[1])
from_list(Msg, list(topic = "orders", size = 12))
#> <Msg>
#>   topic : "orders"
#>   size  : 12L
from_list(Msg, list(topic = "orders", size = 12, extra = "ignored"))
#> <Msg>
#>   topic : "orders"
#>   size  : 12L
try(from_list(Msg, list(topic = "orders")))
#> Error : 1 validation problem in Msg
#>   $size  expected int[1], got <missing>