Current section

Files

Jump to
rbt_weave lib weave native.ex
Raw

lib/weave/native.ex

defmodule Weave.Native do
@moduledoc """
NIF wrapper for the `weave_nif` Rust crate.
Provides low-level bindings to the Rust graph engine and image
processing. This module should not be called directly by
application code -- use `Weave.Graph` or `Weave.Image` instead.
"""
use Rustler,
otp_app: :weave,
crate: "weave_nif",
path: "nif"
@doc "Returns `\"ok\"` if the Rust NIF is loaded and functional."
def health_check, do: :erlang.nif_error(:nif_not_loaded)
@doc """
Detects conflict-of-interest patterns in a subgraph.
Both arguments are JSON strings. Returns the detected patterns as
a JSON string on success, or raises on NIF load failure.
This function runs on a dirty CPU scheduler so it does not block
the normal BEAM schedulers.
"""
def detect_conflicts(_subgraph_json, _opts_json),
do: :erlang.nif_error(:nif_not_loaded)
@doc """
Computes the thumbnail storage key from a source URL.
Returns `"thumbnails/{sha256_hex[0..32]}.webp"`.
"""
def thumbnail_key(_source_url),
do: :erlang.nif_error(:nif_not_loaded)
@doc """
Downloads an image, resizes to 256x256 WebP, and computes the storage key.
Returns `{:ok, {key, webp_bytes}}` or `{:error, reason}`.
This function runs on a dirty CPU scheduler.
"""
def process_thumbnail(_url),
do: :erlang.nif_error(:nif_not_loaded)
end