plushie/ffi
Erlang FFI wrappers for port operations, error handling, and unique ID generation.
Types
Values
pub fn arch_string() -> String
Return the CPU architecture as a string (x86_64, aarch64, or raw).
pub fn extract_eof(
msg: dynamic.Dynamic,
) -> Result(Nil, dynamic.Dynamic)
Extract eof signal from a port message {Port, eof}.
pub fn extract_exit_status(
msg: dynamic.Dynamic,
) -> Result(dynamic.Dynamic, dynamic.Dynamic)
Extract exit status from an Erlang port message tuple.
pub fn extract_line_data(
msg: dynamic.Dynamic,
) -> Result(LineData, dynamic.Dynamic)
Extract line data from a port message in {line, N} mode. Returns Eol for complete lines, Noeol for partial chunks.
pub fn extract_port_data(
msg: dynamic.Dynamic,
) -> Result(dynamic.Dynamic, dynamic.Dynamic)
Extract data payload from an Erlang port message tuple. Works for {packet, N} mode where data is a plain binary.
pub fn file_exists(path: String) -> Bool
Check whether a file exists at the given path.
pub fn file_watcher_subscribe(pid: dynamic.Dynamic) -> Nil
Subscribe the calling process to file events from the watcher.
pub fn json_port_options() -> dynamic.Dynamic
Port options for JSONL wire format (newline-delimited).
pub fn list_beam_files(
dir: String,
) -> List(#(dynamic.Dynamic, dynamic.Dynamic))
List .beam files in a directory, returning (module_atom, mtime) tuples.
pub fn monotonic_time_ms() -> Int
Return the current monotonic time in milliseconds.
pub fn msgpack_port_options() -> dynamic.Dynamic
Port options for MessagePack wire format (4-byte length prefix).
pub fn null_port() -> port.Port
Return a null port value for iostream transport (never used for I/O).
pub fn open_fd_port(
input_fd: Int,
output_fd: Int,
options: dynamic.Dynamic,
) -> port.Port
Open an fd port (for stdin/stdout stdio transport).
pub fn open_port_spawn(
path: String,
args: List(String),
env: dynamic.Dynamic,
options: dynamic.Dynamic,
) -> port.Port
Open a port to spawn an external process. Uses {spawn_executable, Path} with explicit args and environment.
pub fn platform_string() -> String
Return the platform as a string (linux, darwin, windows, unknown).
pub fn port_command(port: port.Port, data: BitArray) -> Bool
Send data to a port. Returns True on success.
pub fn reload_modules(modules: List(dynamic.Dynamic)) -> Nil
Reload a list of module atoms (purge + load_file).
pub fn sha256_hex(data: BitArray) -> String
Compute SHA-256 hash and return as lowercase hex string.
pub fn stable_hash_key(value: dynamic.Dynamic) -> String
Return a stable hash key for any value as a string. Uses erlang:phash2 for consistent results regardless of how the value is wrapped (raw term vs Dynamic).
pub fn start_file_watcher(dirs: List(String)) -> dynamic.Dynamic
Start a file_system watcher on the given directories.
pub fn stdio_port_options_json() -> dynamic.Dynamic
Port options for stdio transport with JSON (eof, no exit_status).
pub fn stdio_port_options_msgpack() -> dynamic.Dynamic
Port options for stdio transport with MessagePack (eof, no exit_status).
pub fn try_call(f: fn() -> a) -> Result(a, dynamic.Dynamic)
Call a function with try/catch error handling. Catches panics and exceptions, returning Result.