# `RustQ.Type`
[🔗](https://github.com/dannote/rustq/blob/v0.11.1/lib/rustq/type.ex#L1)

Built-in Rust/Rustler type vocabulary for `RustQ.Meta.defrust/2` specs.

Prefer ordinary Elixir types when they fit. `RustQ.Meta` maps built-ins such
as `atom()`, `term()`, `boolean()`, `integer()`, `float()`, and `binary()` to
Rust/Rustler types. Use ordinary remote types for external Rust paths where
possible: `SkiaSafe.Canvas.t()` renders as `skia_safe::Canvas`, and
`GeneratedOpts.OvalOpts.t(R.lifetime(:a))` renders as
`generated_opts::OvalOpts<'a>`. Use this module where Rust needs extra
precision or syntax that Elixir types cannot express cleanly: fixed-width
numbers, enum intent markers, references, lifetimes, slices, `NifResult`,
`Vec`, and unit.

    alias RustQ.Type, as: R

    @spec draw(R.ref(SkiaSafe.Canvas.t()), R.f32(), R.f32()) :: R.nif_result(R.unit())
    defrust draw(canvas, x, y) do
      canvas.translate({x, y})
      :ok
    end

    @spec decode_mode(atom()) :: R.nif_result(Mode.t())
    defrust decode_mode(atom) do
      # atom() maps to Rustler Atom
    end

The functions with matching names are marker helpers for non-typespec macro
contexts and for the reserved built-in names (`R.atom()`, `R.bool()`,
`R.term()`). They are not runtime APIs.

# `enum`

```elixir
@type enum(name_or_variants) :: atom() | {name_or_variants}
```

Enum intent marker for domain-specific descriptor resolution, or explicit Rust enum variants when used in a type alias.

# `f32`

```elixir
@type f32() :: float()
```

Rust `f32`.

# `f64`

```elixir
@type f64() :: float()
```

Rust `f64`.

# `i8`

```elixir
@type i8() :: integer()
```

Rust `i8`.

# `i16`

```elixir
@type i16() :: integer()
```

Rust `i16`.

# `i32`

```elixir
@type i32() :: integer()
```

Rust `i32`.

# `i64`

```elixir
@type i64() :: integer()
```

Rust `i64`.

# `isize`

```elixir
@type isize() :: integer()
```

Rust `isize`.

# `lifetime`

```elixir
@type lifetime(name) :: {name, term()}
```

Rust lifetime marker for external remote types and low-level `R.path/2`.

# `mut_ref`

```elixir
@type mut_ref(t) :: t
```

Rust mutable reference `&mut T`.

# `nif_error`

```elixir
@type nif_error() :: atom()
```

Rustler NIF error marker.

# `nif_result`

```elixir
@type nif_result(t) :: {:ok, t} | {:error, nif_error()}
```

Rustler `NifResult<T>`.

# `option`

```elixir
@type option(t) :: nil | t
```

Rust `Option<T>`.

# `path`

```elixir
@type path(parts) :: {parts, term()}
```

Low-level explicit Rust path marker. Prefer ordinary remote types such as `GeneratedOpts.OvalOpts.t(...)` when possible.

# `path`

```elixir
@type path(parts, opts) :: {parts, opts, term()}
```

Low-level explicit Rust path marker with options such as `R.lifetime(:a)`. Prefer ordinary remote types when possible.

# `raw`

```elixir
@type raw(name) :: {name, term()}
```

Raw Rust type fragment marker for syntax Elixir typespecs cannot model. Prefer structural markers such as `R.slice/1` when possible.

# `ref`

```elixir
@type ref(t) :: t
```

Rust shared reference `&T`.

# `result`

```elixir
@type result(ok, error) :: {:ok, ok} | {:error, error}
```

Rust `Result<Ok, Error>`.

# `slice`

```elixir
@type slice(t) :: {t, term()}
```

Rust slice reference `&[T]`.

# `str`

```elixir
@type str() :: binary()
```

Rust string slice `&str`.

# `u8`

```elixir
@type u8() :: 0..255
```

Rust `u8`.

# `u16`

```elixir
@type u16() :: non_neg_integer()
```

Rust `u16`.

# `u32`

```elixir
@type u32() :: non_neg_integer()
```

Rust `u32`.

# `u64`

```elixir
@type u64() :: non_neg_integer()
```

Rust `u64`.

# `unit`

```elixir
@type unit() :: :ok
```

Rust `()`; represented as `:ok`/unit-ish data in Elixir specs.

# `usize`

```elixir
@type usize() :: non_neg_integer()
```

Rust `usize`.

# `vec`

```elixir
@type vec(t) :: [t]
```

Rust `Vec<T>`.

# `atom`

```elixir
@spec atom() :: no_return()
```

# `bool`

```elixir
@spec bool() :: no_return()
```

# `enum`

```elixir
@spec enum(term()) :: no_return()
```

# `f32`

```elixir
@spec f32() :: no_return()
```

# `f64`

```elixir
@spec f64() :: no_return()
```

# `i8`

```elixir
@spec i8() :: no_return()
```

# `i16`

```elixir
@spec i16() :: no_return()
```

# `i32`

```elixir
@spec i32() :: no_return()
```

# `i64`

```elixir
@spec i64() :: no_return()
```

# `isize`

```elixir
@spec isize() :: no_return()
```

# `lifetime`

```elixir
@spec lifetime(term()) :: no_return()
```

# `mut_ref`

```elixir
@spec mut_ref(term()) :: no_return()
```

# `nif_result`

```elixir
@spec nif_result(term()) :: no_return()
```

# `option`

```elixir
@spec option(term()) :: no_return()
```

# `path`

```elixir
@spec path(term()) :: no_return()
```

# `path`

```elixir
@spec path(term(), term()) :: no_return()
```

# `raw`

```elixir
@spec raw(term()) :: no_return()
```

# `ref`

```elixir
@spec ref(term()) :: no_return()
```

# `result`

```elixir
@spec result(term(), term()) :: no_return()
```

# `slice`

```elixir
@spec slice(term()) :: no_return()
```

# `str`

```elixir
@spec str() :: no_return()
```

# `term`

```elixir
@spec term() :: no_return()
```

# `u8`

```elixir
@spec u8() :: no_return()
```

# `u16`

```elixir
@spec u16() :: no_return()
```

# `u32`

```elixir
@spec u32() :: no_return()
```

# `u64`

```elixir
@spec u64() :: no_return()
```

# `unit`

```elixir
@spec unit() :: no_return()
```

# `usize`

```elixir
@spec usize() :: no_return()
```

# `vec`

```elixir
@spec vec(term()) :: no_return()
```

---

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