# `RustQ.Rustler.Schema`
[🔗](https://github.com/dannote/rustq/blob/v0.11.1/lib/rustq/rustler/schema.ex#L1)

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
    end

Field optionality is encoded in the Rust type (`{:option, :String}`), keeping
the schema close to the generated Rust.

# `enum_decl`

```elixir
@type enum_decl() :: {atom(), keyword()}
```

# `field`

```elixir
@type field() :: {atom(), rust_type(), keyword()}
```

# `rust_type`

```elixir
@type rust_type() :: RustQ.Rust.AST.type() | String.t() | atom() | tuple()
```

# `schema_node`

```elixir
@type schema_node() :: {atom(), [field()], keyword()}
```

# `t`

```elixir
@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_alias`

```elixir
@type type_alias() :: {atom(), rust_type()}
```

# `default_attrs`
*macro* 

Sets default Rust attributes for generated schema items.

# `node`
*macro* 

Declares an Elixir struct-backed Rust `NifStruct` node.

# `rust_items`

```elixir
@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.

# `rust_prefix`
*macro* 

Overrides the Rust type-name prefix for the current schema.

# `schema`
*macro* 

Declares a Rustler schema for an Elixir module namespace.

# `shorthand_fields`

```elixir
@spec shorthand_fields([atom() | String.t()]) :: [RustQ.Rust.Fragment.t()]
```

Builds shorthand field fragments for Rust template splices.

# `struct_fields`

```elixir
@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.

# `tag_field`
*macro* 

Sets the atom-keyed field used to identify tagged values.

# `tagged_enum`
*macro* 

Declares a tagged enum over selected schema nodes.

# `type`
*macro* 

Declares a reusable schema-local Rust type alias.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
