RustQ.Rustler.Term (rustq v1.0.0-rc.19)

Copy Markdown View Source

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.

Summary

Functions

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

The RustQ AST of each defrust definition.

Callable metadata for the module's definitions.

The Rust items the module generates, in order.

The module's defrustmacro definitions.

The macro_rules! items defrustmacro emits.

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

The Rust source the module generates.

The RustQ AST of each declared Rust type.

The Rust items the module's types generate.

The Rust types the module's @types declare.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Builds common map access and term decoding helpers.

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

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

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

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

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

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

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

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

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

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

Functions

__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 defrustmods 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 @types declare.

bool_val(arg1, arg2)

@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(opts \\ [])

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

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

cached_struct_keys(arg1, arg2, arg3)

@spec cached_struct_keys(
  RustQ.Type.raw(:"Env<'_>"),
  RustQ.Type.raw(:"&'static OnceLock<Vec<Atom>>"),
  RustQ.Type.raw(:"&[&str]")
) :: RustQ.Type.raw(:"&'static [Atom]")

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

decoder(name, opts)

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

default_struct_values(arg1, arg2, arg3)

@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(name, opts)

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

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

encoder_atom_names(opts)

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

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

encoder_atoms_from_source(source, roots, opts \\ [])

@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(source, roots, opts \\ [])

@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(arg1, arg2)

@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(arg1, arg2)

@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(arg1, arg2)

@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(arg1, arg2)

@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(arg1, arg2)

@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(arg1, arg2)

@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(arg1, arg2)

@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(arg1, arg2)

@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(arg1, arg2)

@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(opts \\ [])

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

Builds common map access and term decoding helpers.

is_nil(arg1)

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

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

list_val(arg1, arg2)

@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(arg1, arg2)

@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(arg1, arg2, arg3)

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

make_struct_from_terms(arg1, arg2, arg3)

@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(arg1, arg2)

@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(arg1, arg2)

@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(arg1)

@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(arg1, arg2)

@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(arg1)

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

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