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
DirtyIoscheduler - 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 Rustpanic!becomes an Elixir exception; segfaults fromunsafecode are still fatal. - More complex deployment than the Port backend.
Configuration
config :ex_maude,
backend: :nifPrecompiled 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
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
Functions
@spec alive?(GenServer.server()) :: boolean()
Checks if the NIF backend is alive.
Returns a specification to start this module under a supervisor.
See Supervisor.
@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)
@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)
@spec start_link(keyword()) :: GenServer.on_start()
Starts the NIF backend worker.
Options
:maude_path- Path to Maude executable (optional, auto-detected)
@spec stop(GenServer.server()) :: :ok
Stops the NIF backend worker.