RustQ.Rustler.Nif (rustq v0.11.1)

Copy Markdown View Source

Generates Rustler NIF wrappers, stubs, NifStruct declarations, and raw NIF_TERM builders.

Most helpers in this module use RustQ AST. The raw NIF_TERM builders are an explicit low-level Rustler escape boundary for unsafe wrapper APIs; prefer RustQ.Rustler.Term helpers when normal Term<'a> values are available.

Summary

Functions

Returns selected, export-named Rust function metadata from one source file.

Returns selected, export-named Rust function metadata from multiple source groups.

Builds the rustler::init! declaration for an Elixir module.

Builds unsafe raw NIF_TERM map and struct helpers.

Builds a Rust struct deriving NifStruct for an Elixir struct module.

Builds an Elixir stub module from mixed RustQ.Syn.Function and RustQ AST metadata.

Builds an Elixir NIF-not-loaded stub module from one Rust source file.

Builds one Elixir NIF-not-loaded stub module from multiple Rust source groups.

Builds one NIF wrapper that delegates to an implementation function.

Builds NIF wrappers from explicit export specifications.

Builds NIF wrappers whose signatures are derived from Rust functions in one source file.

Builds NIF wrappers from multiple {source_path, specs} groups.

Types

spec()

@type spec() :: {atom() | String.t(), keyword()}

Functions

functions_from_source(path, specs, defaults \\ [])

@spec functions_from_source(Path.t(), [spec()], keyword()) :: [
  {atom() | String.t(), RustQ.Syn.Function.t()}
]

Returns selected, export-named Rust function metadata from one source file.

functions_from_sources(groups, defaults \\ [])

@spec functions_from_sources(
  [{Path.t(), [spec()]}],
  keyword()
) :: [{atom() | String.t(), RustQ.Syn.Function.t()}]

Returns selected, export-named Rust function metadata from multiple source groups.

init(module)

Builds the rustler::init! declaration for an Elixir module.

raw_term_builders(opts \\ [])

@spec raw_term_builders(keyword()) :: [RustQ.Rust.Fragment.t()]

Builds unsafe raw NIF_TERM map and struct helpers.

struct(name, module, opts \\ [])

@spec struct(atom() | String.t(), module() | String.t(), keyword()) ::
  RustQ.Rust.AST.Struct.t()

Builds a Rust struct deriving NifStruct for an Elixir struct module.

stubs_from_functions(functions, module)

@spec stubs_from_functions(
  [RustQ.Syn.Function.t() | RustQ.Rust.AST.Function.t() | {term(), term()}],
  module()
) :: String.t()

Builds an Elixir stub module from mixed RustQ.Syn.Function and RustQ AST metadata.

stubs_from_source(path, specs, module, defaults \\ [])

@spec stubs_from_source(Path.t(), [spec()], module(), keyword()) :: String.t()

Builds an Elixir NIF-not-loaded stub module from one Rust source file.

stubs_from_sources(groups, module, defaults \\ [])

@spec stubs_from_sources([{Path.t(), [spec()]}], module(), keyword()) :: String.t()

Builds one Elixir NIF-not-loaded stub module from multiple Rust source groups.

wrapper(name, opts)

@spec wrapper(
  atom() | String.t(),
  keyword()
) :: RustQ.Rust.AST.Function.t()

Builds one NIF wrapper that delegates to an implementation function.

wrappers(specs)

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

Builds NIF wrappers from explicit export specifications.

wrappers_from_source(path, specs, defaults \\ [])

@spec wrappers_from_source(Path.t(), [spec()], keyword()) :: [
  RustQ.Rust.AST.Function.t()
]

Builds NIF wrappers whose signatures are derived from Rust functions in one source file.

wrappers_from_sources(groups, defaults \\ [])

@spec wrappers_from_sources(
  [{Path.t(), [spec()]}],
  keyword()
) :: [RustQ.Rust.AST.Function.t()]

Builds NIF wrappers from multiple {source_path, specs} groups.