Schema DSL for generating Rustler structs and tagged enums.
Use this when a group of Elixir structs should be mirrored in Rust. A schema
module defines nodes, fields, type aliases, and tagged enums; rust_items/1
returns Rust fragments ready for rustq.exs.
defmodule MyApp.Codegen.ContentSchema do
use RustQ.Rustler.Schema
schema MyApp.Content do
node Text do
field :text, :String
field :size, {:option, :String}
end
node Paragraph do
field :body, {:vec, Content}
end
tagged_enum Content do
variants :all
end
end
endField optionality is encoded in the Rust type ({:option, :String}), keeping
the schema close to the generated Rust.
Summary
Types
@type field() :: {atom(), RustQ.Rust.rust_type(), keyword()}
@type t() :: %RustQ.Rustler.Schema{ default_attrs: [term()], enums: [enum_decl()], module_prefix: module(), nodes: [schema_node()], rust_prefix: String.t(), tag_field: atom(), type_aliases: [type_alias()] }
@type type_alias() :: {atom(), RustQ.Rust.rust_type()}