RustQ.Type (rustq v0.6.0)

Copy Markdown View Source

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.

Summary

Types

Enum intent marker for domain-specific descriptor resolution.

Rust f32.

Rust f64.

Rust i64.

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

Rust mutable reference &mut T.

Rustler NIF error marker.

Rustler NifResult<T>.

Rust Option<T>.

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

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

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

Rust shared reference &T.

Rust Result<Ok, Error>.

Rust slice reference &[T].

Rust string slice &str.

Rust u8.

Rust u32.

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

Rust Vec<T>.

Types

enum(name)

@type enum(name) :: atom() | {name}

Enum intent marker for domain-specific descriptor resolution.

f32()

@type f32() :: float()

Rust f32.

f64()

@type f64() :: float()

Rust f64.

i64()

@type i64() :: integer()

Rust i64.

lifetime(name)

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

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

mut_ref(t)

@type mut_ref(t) :: t

Rust mutable reference &mut T.

nif_error()

@type nif_error() :: atom()

Rustler NIF error marker.

nif_result(t)

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

Rustler NifResult<T>.

option(t)

@type option(t) :: nil | t

Rust Option<T>.

path(parts)

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

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

path(parts, opts)

@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(name)

@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(t)

@type ref(t) :: t

Rust shared reference &T.

result(ok, error)

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

Rust Result<Ok, Error>.

slice(t)

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

Rust slice reference &[T].

str()

@type str() :: binary()

Rust string slice &str.

u8()

@type u8() :: 0..255

Rust u8.

u32()

@type u32() :: non_neg_integer()

Rust u32.

unit()

@type unit() :: :ok

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

vec(t)

@type vec(t) :: [t]

Rust Vec<T>.

Functions

atom()

@spec atom() :: no_return()

bool()

@spec bool() :: no_return()

enum(name)

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

f32()

@spec f32() :: no_return()

f64()

@spec f64() :: no_return()

i8()

@spec i8() :: no_return()

i16()

@spec i16() :: no_return()

i32()

@spec i32() :: no_return()

i64()

@spec i64() :: no_return()

isize()

@spec isize() :: no_return()

lifetime(name)

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

mut_ref(type)

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

nif_result(type)

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

option(type)

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

path(parts)

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

path(parts, opts)

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

raw(name)

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

ref(type)

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

result(ok, error)

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

slice(type)

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

str()

@spec str() :: no_return()

term()

@spec term() :: no_return()

u8()

@spec u8() :: no_return()

u16()

@spec u16() :: no_return()

u32()

@spec u32() :: no_return()

u64()

@spec u64() :: no_return()

unit()

@spec unit() :: no_return()

usize()

@spec usize() :: no_return()

vec(type)

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