Kettlecorn.Struct (kettlecorn v0.1.0)

Copy Markdown View Source

A guest struct represented as data: its module and fields.

Kettlecorn.ETF produces this wrapper when the module atom exists on the host. Otherwise the value stays a map with __struct__: {:unknown_atom, name}.

Decoding it as a struct of module would allow that module's protocol implementations to run on the host with guest-supplied fields. Validate the fields before constructing a host struct:

case value do
  %Kettlecorn.Struct{module: MyApp.Order, fields: fields} -> MyApp.Order.new(fields)
  _other -> {:error, :unexpected_value}
end

The Validating guest data notebook validates quotes and dates, including structs nested in other data.

Summary

Types

t()

@type t() :: %Kettlecorn.Struct{fields: map(), module: atom()}