# `ExCodecs.Native`
[🔗](https://github.com/AnimaLogica/codecs/blob/v0.2.4/lib/ex_codecs/native.ex#L2)

Native NIF module providing Rust-based compression implementations.

This module loads precompiled NIF binaries for Zstd, LZ4, Snappy, Bzip2,
Blosc (Blosc1 chunks), Blosc2 and CRC32C via `RustlerPrecompiled`. If a precompiled
artifact is not available for the current platform, it falls back to compiling
the Rust NIF from source (requires the Rust toolchain).

If the NIF fails to load entirely, all functions fall back to
`:erlang.nif_error(:nif_not_loaded)`, and codecs are registered as unavailable
at startup.

> **Note**: This module is excluded from coverage because all functions are
> Rustler NIF stubs that are replaced at load time by the native implementation.

# `nif_loaded?`

```elixir
@spec nif_loaded?() :: boolean()
```

Returns `true` when the native NIF library is loaded.

The check calls the native `codec_versions/0` function and verifies that it
returns a map. This function is primarily useful for startup diagnostics;
public compression calls already convert an unavailable NIF into
`%ExCodecs.Error{reason: :nif_not_loaded}`.

## Arguments

This function takes no arguments.

## Returns

  * `true` when the native library responds with its codec-version map.
  * `false` when the NIF stub raises `ErlangError` or `ArgumentError`.

## Raises

Expected NIF-loading errors are caught. An exception of another class raised
by the native implementation is not caught and propagates to the caller.

## Example

    iex> loaded? = ExCodecs.Native.nif_loaded?()
    iex> is_boolean(loaded?)
    true

---

*Consult [api-reference.md](api-reference.md) for complete listing*
