RustQ.Meta.Type (rustq v0.9.3)

Copy Markdown View Source

Structural metadata for an Elixir typespec lowered by RustQ.

RustQ.Spec.type/2 and RustQ.Spec.aliases/1 return this struct. The :kind field is the primary semantic classification (:f64, :bool, :tuple, :struct, :enum, :type, and so on). The :ast field carries the RustQ Rust type AST used for rendering, :rust is its rendered Rust type, and :meta carries shape-specific metadata such as:

  • :elements for tuple element types
  • :fields for map/struct field types
  • :elixir_name for local aliases and enum aliases
  • :elixir_module, :elixir_type, and :elixir_args for external Elixir remote types such as Skia.Path.t()

Prefer consuming this structure directly at codegen boundaries instead of parsing rendered Rust type strings.

Summary

Functions

Returns the semantic category for a lowered RustQ type.

Returns true when two lowered types are semantically compatible.

Returns true when a value type can satisfy a callable expected argument type.

Returns the natural Rusty-Elixir input type for a callable expected type.

Returns the concrete value type expected by a callable argument.

Returns true when a type originated from a specific Elixir remote type.

Converts structured RustQ.Syn.Type metadata into a RustQ meta type.

Returns the success/inner type of Result, NifResult, or Option wrappers.

Returns true when the type AST structurally contains the given lifetime.

Returns true for wrapper types that can propagate with Rust ?.

Returns the referenced inner type for &T or &mut T metadata.

Returns the element type for [T] / &[T] metadata.

Constructs Vec<T> type metadata.

Returns the element type for Vec<T> metadata.

Types

category()

@type category() ::
  :number
  | :integer
  | :boolean
  | :atom
  | :string
  | :term
  | :enum
  | {:tuple, [t()]}
  | {:alias, atom()}
  | :type

t()

@type t() :: %RustQ.Meta.Type{
  ast: term(),
  kind: atom(),
  meta: map(),
  rust: String.t()
}

Functions

category(type)

@spec category(t()) :: category()

Returns the semantic category for a lowered RustQ type.

compatible?(left, right)

@spec compatible?(t() | nil, t() | nil) :: boolean()

Returns true when two lowered types are semantically compatible.

compatible_with_expected?(value, expected)

@spec compatible_with_expected?(t() | nil, t() | nil) :: boolean()

Returns true when a value type can satisfy a callable expected argument type.

expected_input(type)

@spec expected_input(t()) :: t()

Returns the natural Rusty-Elixir input type for a callable expected type.

This normalizes Rust adapter types into the value shape an author should pass before call-site coercions are emitted. For example, &T expects an authored T, &[T] expects an authored Vec<T>, and impl IntoIterator<Item = T> expects an authored Vec<T>.

expected_value(type)

@spec expected_value(t()) :: t()

Returns the concrete value type expected by a callable argument.

This peels structural argument adapters such as impl Into<T> and the common impl Into<Option<(A, B)>> tuple case so propagation inference can compare a decoder's success type with the value the Rust call actually expects.

external?(type, module, type)

@spec external?(t(), module(), atom()) :: boolean()

Returns true when a type originated from a specific Elixir remote type.

from_syn(path)

@spec from_syn(RustQ.Syn.type()) :: t()

Converts structured RustQ.Syn.Type metadata into a RustQ meta type.

This is the first bridge from upstream Rust signatures into Rusty-Elixir type metadata. It preserves structured wrappers such as refs, options, results, slices, and paths, while falling back to TypeRaw for Syn shapes that do not yet expose enough structure to rebuild a richer RustQ AST node.

inner(type)

@spec inner(t()) :: t() | nil

Returns the success/inner type of Result, NifResult, or Option wrappers.

lifetime?(type, lifetime \\ :a)

@spec lifetime?(t(), atom()) :: boolean()

Returns true when the type AST structurally contains the given lifetime.

parse(union, aliases)

@spec parse(Macro.t(), map()) :: t()

propagates?(type)

@spec propagates?(t()) :: boolean()

Returns true for wrapper types that can propagate with Rust ?.

ref_inner(type)

@spec ref_inner(t()) :: t() | nil

Returns the referenced inner type for &T or &mut T metadata.

slice_inner(type)

@spec slice_inner(t()) :: t() | nil

Returns the element type for [T] / &[T] metadata.

vec(inner)

@spec vec(t()) :: t()

Constructs Vec<T> type metadata.

vec_inner(type)

@spec vec_inner(t()) :: t() | nil

Returns the element type for Vec<T> metadata.