ExMaude.Backend.NIF (ExMaude v0.2.0)

View Source

NIF-based backend for ExMaude using Rustler.

Manages a Maude subprocess from Rust, communicating via stdin/stdout pipes through a dedicated reader thread. Offers the lowest latency of the three backends because there's no Elixir port overhead and no distribution round-trip — but, like any NIF, it shares the BEAM's OS process.

Features

  • Per-command timeouts enforced inside the NIF
  • Runs all blocking operations on the DirtyIo scheduler
  • Structured error returns (:timeout, :eof, :io_error, :lock_poisoned)

Trade-offs

  • No process isolation — a segfault in the NIF crashes the BEAM. Rustler wraps NIF entry points in std::panic::catch_unwind, so a Rust panic! becomes an Elixir exception; segfaults from unsafe code are still fatal.
  • More complex deployment than the Port backend.

Configuration

config :ex_maude,
  backend: :nif

Precompiled Binaries

Precompiled NIF binaries are downloaded automatically for supported platforms (macOS aarch64/x86_64, Linux gnu/musl × aarch64/x86_64, Windows gnu/msvc). To force a build from source (requires Rust toolchain):

EX_MAUDE_BUILD=1 mix deps.compile ex_maude

Summary

Types

t()

Internal state for the NIF backend GenServer.

Functions

Checks if the NIF backend is alive.

Returns a specification to start this module under a supervisor.

Executes a Maude command via NIF.

Loads a Maude file via NIF.

Starts the NIF backend worker.

Stops the NIF backend worker.

Types

t()

@type t() :: %ExMaude.Backend.NIF{
  handle: reference() | nil,
  maude_path: String.t() | nil
}

Internal state for the NIF backend GenServer.

Functions

alive?(server)

@spec alive?(GenServer.server()) :: boolean()

Checks if the NIF backend is alive.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

execute(server, command, opts \\ [])

@spec execute(GenServer.server(), String.t(), keyword()) ::
  {:ok, String.t()} | {:error, term()}

Executes a Maude command via NIF.

Options

  • :timeout - Maximum time to wait in milliseconds (default: 30000)

load_file(server, path)

@spec load_file(GenServer.server(), Path.t()) :: :ok | {:error, term()}

Loads a Maude file via NIF.

Options

  • :timeout - Maximum time to wait in milliseconds (default: 30000)

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Starts the NIF backend worker.

Options

  • :maude_path - Path to Maude executable (optional, auto-detected)

stop(server)

@spec stop(GenServer.server()) :: :ok

Stops the NIF backend worker.