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
Functions
Sets default Rust attributes for generated schema items.
Declares an Elixir struct-backed Rust NifStruct node.
Builds all structural Rust items for a schema.
Overrides the Rust type-name prefix for the current schema.
Declares a Rustler schema for an Elixir module namespace.
Builds shorthand field fragments for Rust template splices.
Builds structural Rust field fragments from {name, type} pairs.
Sets the atom-keyed field used to identify tagged values.
Declares a tagged enum over selected schema nodes.
Declares a reusable schema-local Rust type alias.
Types
@type rust_type() :: RustQ.Rust.AST.type() | String.t() | atom() | tuple()
@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()] }
Functions
Sets default Rust attributes for generated schema items.
Declares an Elixir struct-backed Rust NifStruct node.
@spec rust_items(%RustQ.Rustler.Schema{ default_attrs: term(), enums: term(), module_prefix: term(), nodes: term(), rust_prefix: term(), tag_field: term(), type_aliases: term() }) :: [RustQ.Rust.AST.item()]
Builds all structural Rust items for a schema.
Overrides the Rust type-name prefix for the current schema.
Declares a Rustler schema for an Elixir module namespace.
@spec shorthand_fields([atom() | String.t()]) :: [RustQ.Rust.Fragment.t()]
Builds shorthand field fragments for Rust template splices.
@spec struct_fields( [{atom() | String.t(), RustQ.Rust.AST.type() | String.t()}], keyword() ) :: [RustQ.Rust.AST.StructField.t()]
Builds structural Rust field fragments from {name, type} pairs.
Sets the atom-keyed field used to identify tagged values.
Declares a tagged enum over selected schema nodes.
Declares a reusable schema-local Rust type alias.