RustQ.Test (rustq v1.0.0-rc.4)

Copy Markdown View Source

Composable ExUnit helpers for Rust generated by defrust and defnif.

The helpers return source or boolean values so tests keep using ExUnit's ordinary assert macro, pattern matching, and diffs:

defmodule MyApp.NativeTest do
  use RustQ.Test, async: true

  test "generates and exports the native boundary" do
    assert rust_source!(MyApp.Native, :sum_impl) =~ "fn sum_impl"
    assert nif_exported?(MyApp.Native, :sum, 1)
    assert RustQ.valid?(rust_source!(MyApp.Native), "my_app_native.rs")
  end
end

rust_source!/1 returns a module's complete generated Rust. rust_source!/2 renders one named generated function, which keeps source assertions focused and prevents matches across unrelated functions.

Summary

Functions

Returns whether a function is exported to Elixir and marked as a Rustler NIF.

Returns a generated module's complete Rust source or raises.

Renders one named generated Rust function or raises.

Functions

nif_exported?(module, function, arity)

@spec nif_exported?(module(), atom(), arity()) :: boolean()

Returns whether a function is exported to Elixir and marked as a Rustler NIF.

rust_source!(module)

@spec rust_source!(module()) :: String.t()

Returns a generated module's complete Rust source or raises.

rust_source!(module, function)

@spec rust_source!(module(), atom()) :: String.t()

Renders one named generated Rust function or raises.