# `RustQ.Rustler.Term`
[🔗](https://github.com/elixir-crab/rustq/blob/v1.0.0-rc.19/lib/rustq/rustler/term.ex#L1)

Generates Rustler `Term<'a>` builders, decoders, and map access helpers.

Most helpers are authored with `defrust` or RustQ AST. The remaining
`EscapeExpr` fragments are localized Rustler wrapper-boundary escapes for
unsafe raw term construction or caller-supplied decoder expressions.

# `__mix_recompile__?`

Whether the module's Rust file appeared or went since the module compiled.

# `__rustq_asts__`

The RustQ AST of each `defrust` definition.

# `__rustq_callables__`

Callable metadata for the module's definitions.

# `__rustq_items__`

The Rust items the module generates, in order.

# `__rustq_macro_definitions__`

The module's `defrustmacro` definitions.

# `__rustq_macro_items__`

The `macro_rules!` items `defrustmacro` emits.

# `__rustq_rust_modules__`

The Rust modules the module's `defrustmod`s map its aliases, or itself (`[]`), to.

# `__rustq_source__`

The Rust source the module generates.

# `__rustq_type_asts__`

The RustQ AST of each declared Rust type.

# `__rustq_type_items__`

The Rust items the module's types generate.

# `__rustq_types__`

The Rust types the module's `@type`s declare.

# `bool_val`

```elixir
@spec bool_val(term(), RustQ.Type.path({:rustler, :Atom})) :: boolean()
```

A Rust function `defrust` generates. It runs only as Rust; calling it from Elixir
raises.

# `builders`

```elixir
@spec builders(keyword()) :: [RustQ.Rust.AST.Function.t()]
```

Builds safe `Term<'a>` map and struct construction helpers.

# `cached_struct_keys`

```elixir
@spec cached_struct_keys(
  RustQ.Type.raw(:&quot;Env&lt;'_&gt;&quot;),
  RustQ.Type.raw(:&quot;&amp;'static OnceLock&lt;Vec&lt;Atom&gt;&gt;&quot;),
  RustQ.Type.raw(:&quot;&amp;[&amp;str]&quot;)
) :: RustQ.Type.raw(:&quot;&amp;'static [Atom]&quot;)
```

A Rust function `defrust` generates. It runs only as Rust; calling it from Elixir
raises.

# `decoder`

```elixir
@spec decoder(
  atom() | String.t(),
  keyword()
) :: [RustQ.Rust.AST.Struct.t() | RustQ.Rust.AST.Function.t()]
```

Builds a struct and decoder from an atom-keyed Rustler map term.

# `default_struct_values`

```elixir
@spec default_struct_values(
  RustQ.Type.path(:Env, RustQ.Type.lifetime(:a)),
  RustQ.Type.path(:Atom),
  RustQ.Type.usize()
) :: RustQ.Type.vec(term())
```

A Rust function `defrust` generates. It runs only as Rust; calling it from Elixir
raises.

# `encoder`

```elixir
@spec encoder(
  atom() | String.t(),
  keyword()
) :: RustQ.Rust.AST.Impl.t()
```

Builds a `rustler::Encoder` implementation from structural field metadata.

# `encoder_atom_names`

```elixir
@spec encoder_atom_names(keyword()) :: [String.t()]
```

Returns the Rust atom identifiers referenced by a term encoder manifest.

# `encoder_atoms_from_source`

```elixir
@spec encoder_atoms_from_source(
  RustQ.Syn.Index.t() | [Path.t()],
  [atom() | String.t()],
  keyword()
) :: [String.t() | {atom(), String.t()}]
```

Returns the atom declarations used by `encoders_from_source/3`.

Pass the result to `RustQ.Rustler.Atom.declaration/2` so the atom registry is
derived from the same source as the encoders.

# `encoders_from_source`

```elixir
@spec encoders_from_source(
  RustQ.Syn.Index.t() | [Path.t()],
  [atom() | String.t()],
  keyword()
) :: [
  RustQ.Rust.AST.Function.t()
]
```

Builds `Term` encoder functions for Rust structs and enums read from source.

`source` is a `RustQ.Syn.Index` or a list of Rust source paths. Starting from
`roots`, RustQ follows field and variant payload types through the index and
builds one function per reachable type:

    pub(crate) fn encode_set_prop_ir_node<'a>(env: Env<'a>, value: &SetPropIRNode<'_>) -> Term<'a>

Free functions keep the encoders usable for types owned by another crate.
Structs encode as atom-keyed maps. A newtype struct encodes as its single
field. Unit variants encode as atoms, tuple variants as their payload, and
named variants as maps. `Option` encodes `None` as `nil`, sequences and sets
as lists, and maps as maps.

Every reachable type must be indexed, a wrapper, a scalar, or mapped in
`:external`. Otherwise the call raises and lists the unmapped types, so a
change in the source shows up at generation time.

Options:

- `:tag` — key added to data-carrying enum variants, with the variant atom
  (`SetProp` becomes `:set_prop`) as its value.
- `:external` — `[{type_name, helper}]`; the helper is called with the
  environment and a reference to the value instead of generating an encoder.
- `:wrappers` — type names added to the `:pointer`, `:sequence`, `:set`,
  `:map`, and `:string` roles, for example allocator-aware `Vec` types.
- `:types` — per-type policy: `:except` field names, `:fields` with `:key`
  renames or `:with` helpers, `:variants` atom renames, `:tag`, and
  `transparent: true` to encode a struct with one field as that field.
- `:vis` — function visibility, `:crate` by default.

# `f64_val`

```elixir
@spec f64_val(term(), RustQ.Type.path({:rustler, :Atom})) :: RustQ.Type.f64()
```

A Rust function `defrust` generates. It runs only as Rust; calling it from Elixir
raises.

# `get`

```elixir
@spec get(term(), RustQ.Type.path({:rustler, :Atom})) :: RustQ.Type.option(term())
```

A Rust function `defrust` generates. It runs only as Rust; calling it from Elixir
raises.

# `get_bool`

```elixir
@spec get_bool(term(), RustQ.Type.path({:rustler, :Atom})) ::
  RustQ.Type.option(boolean())
```

A Rust function `defrust` generates. It runs only as Rust; calling it from Elixir
raises.

# `get_i64`

```elixir
@spec get_i64(term(), RustQ.Type.path({:rustler, :Atom})) ::
  RustQ.Type.option(RustQ.Type.i64())
```

A Rust function `defrust` generates. It runs only as Rust; calling it from Elixir
raises.

# `get_map`

```elixir
@spec get_map(term(), RustQ.Type.path({:rustler, :Atom})) :: RustQ.Type.option(term())
```

A Rust function `defrust` generates. It runs only as Rust; calling it from Elixir
raises.

# `get_optional_string`

```elixir
@spec get_optional_string(term(), RustQ.Type.path({:rustler, :Atom})) ::
  RustQ.Type.option(RustQ.Type.option(String.t()))
```

A Rust function `defrust` generates. It runs only as Rust; calling it from Elixir
raises.

# `get_string`

```elixir
@spec get_string(term(), RustQ.Type.path({:rustler, :Atom})) ::
  RustQ.Type.option(String.t())
```

A Rust function `defrust` generates. It runs only as Rust; calling it from Elixir
raises.

# `get_string_list`

```elixir
@spec get_string_list(term(), RustQ.Type.path({:rustler, :Atom})) ::
  RustQ.Type.option(RustQ.Type.vec(String.t()))
```

A Rust function `defrust` generates. It runs only as Rust; calling it from Elixir
raises.

# `get_term_list`

```elixir
@spec get_term_list(term(), RustQ.Type.path({:rustler, :Atom})) ::
  RustQ.Type.option(RustQ.Type.vec(term()))
```

A Rust function `defrust` generates. It runs only as Rust; calling it from Elixir
raises.

# `helpers`

```elixir
@spec helpers(keyword()) :: [RustQ.Rust.AST.Function.t()]
```

Builds common map access and term decoding helpers.

# `is_nil`

```elixir
@spec is_nil(term()) :: boolean()
```

A Rust function `defrust` generates. It runs only as Rust; calling it from Elixir
raises.

# `list_val`

```elixir
@spec list_val(term(), RustQ.Type.path({:rustler, :Atom})) :: RustQ.Type.vec(term())
```

A Rust function `defrust` generates. It runs only as Rust; calling it from Elixir
raises.

# `make_map_from_terms`

```elixir
@spec make_map_from_terms(
  RustQ.Type.path(:Env, RustQ.Type.lifetime(:a)),
  RustQ.Type.slice({term(), term()})
) :: RustQ.Type.nif_result(term())
```

A Rust function `defrust` generates. It runs only as Rust; calling it from Elixir
raises.

# `make_struct_from_arrays`

```elixir
@spec make_struct_from_arrays(
  RustQ.Type.path(:Env, RustQ.Type.lifetime(:a)),
  RustQ.Type.slice(RustQ.Type.path(:Atom)),
  RustQ.Type.slice(term())
) :: RustQ.Type.nif_result(term())
```

A Rust function `defrust` generates. It runs only as Rust; calling it from Elixir
raises.

# `make_struct_from_terms`

```elixir
@spec make_struct_from_terms(
  RustQ.Type.path(:Env, RustQ.Type.lifetime(:a)),
  RustQ.Type.slice(term()),
  RustQ.Type.slice(term())
) :: RustQ.Type.nif_result(term())
```

A Rust function `defrust` generates. It runs only as Rust; calling it from Elixir
raises.

# `opt`

```elixir
@spec opt(term(), RustQ.Type.path({:rustler, :Atom})) :: RustQ.Type.option(term())
```

A Rust function `defrust` generates. It runs only as Rust; calling it from Elixir
raises.

# `str_val`

```elixir
@spec str_val(term(), RustQ.Type.path({:rustler, :Atom})) :: String.t()
```

A Rust function `defrust` generates. It runs only as Rust; calling it from Elixir
raises.

# `type_atom`

```elixir
@spec type_atom(term()) :: RustQ.Type.option(RustQ.Type.path({:rustler, :Atom}))
```

A Rust function `defrust` generates. It runs only as Rust; calling it from Elixir
raises.

# `type_eq`

```elixir
@spec type_eq(term(), RustQ.Type.path({:rustler, :Atom})) :: boolean()
```

A Rust function `defrust` generates. It runs only as Rust; calling it from Elixir
raises.

# `type_str`

```elixir
@spec type_str(term()) :: String.t()
```

A Rust function `defrust` generates. It runs only as Rust; calling it from Elixir
raises.

---

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