RustQ.Rust (rustq v0.1.2)

Copy Markdown View Source

Elixir-friendly builders for Rust fragments.

Use this module when generating Rust declarations from data. Builders return small structs or fragments that RustQ can validate and splice into templates.

alias RustQ.Rust

Rust.struct(:User,
  vis: :pub,
  derive: [:Clone, :Debug],
  fields: [Rust.field(:id, :i64, vis: :pub)]
)

Prefer real Rust templates for larger bodies and use these builders for the repetitive edges: fields, function signatures, attributes, type aliases, and simple declarations.

Summary

Types

rust_type()

@type rust_type() :: atom() | String.t() | tuple() | [atom() | String.t()]

Functions

arg(function, arg)

arg(function, name, type, opts \\ [])

args(function, args)

arm(code)

@spec arm(iodata()) :: RustQ.Rust.Fragment.t()

arm(pattern, body)

@spec arm(iodata(), iodata()) :: RustQ.Rust.Fragment.t()

attr(item, attr)

@spec attr(term(), term()) :: term()

body(function, body)

const(name, type, value, opts \\ [])

@spec const(atom() | String.t(), rust_type(), term(), keyword()) ::
  RustQ.Rust.Const.t()

derive(item, values)

enum(name, opts \\ [])

@spec enum(
  atom() | String.t(),
  keyword()
) :: RustQ.Rust.EnumDecl.t()

expr(code)

@spec expr(iodata()) :: RustQ.Rust.Fragment.t()

field(name, type)

@spec field(atom() | String.t(), rust_type()) :: RustQ.Rust.Field.t()

field(name, type, opts)

@spec field(atom() | String.t(), rust_type(), keyword()) :: RustQ.Rust.Field.t()

field(item, name, type, opts)

fields(item, fields)

@spec fields(RustQ.Rust.Struct.t(), [term()]) :: RustQ.Rust.Struct.t()

fn(clauses)

Alias for fn_/2, callable as RustQ.Rust.fn(...).

fn_(name, opts \\ [])

@spec fn_(
  atom() | String.t(),
  keyword()
) :: RustQ.Rust.Function.t()

impl(target, opts \\ [])

@spec impl(
  rust_type(),
  keyword()
) :: RustQ.Rust.Impl.t()

impl_item(code)

@spec impl_item(iodata()) :: RustQ.Rust.Fragment.t()

item(code)

@spec item(iodata()) :: RustQ.Rust.Fragment.t()

item(impl, item)

items(impl, items)

literal(value)

@spec literal(term()) :: String.t()

mod(name, opts \\ [])

@spec mod(
  atom() | String.t(),
  keyword()
) :: RustQ.Rust.ModDecl.t()

param(name, type)

@spec param(atom() | String.t(), rust_type()) :: RustQ.Rust.Fragment.t()

path(parts)

@spec path(term()) :: String.t()

prelude(atom)

@spec prelude(atom()) :: [RustQ.Rust.Use.t()]

pub(item)

@spec pub(term()) :: term()

raw(code)

@spec raw(iodata()) :: RustQ.Rust.Fragment.t()

ref(value, opts \\ [])

@spec ref(
  rust_type(),
  keyword()
) :: String.t()

returns(function, type)

static_slice(value)

@spec static_slice(rust_type()) :: String.t()

stmt(code)

@spec stmt(iodata()) :: RustQ.Rust.Fragment.t()

struct(name, opts \\ [])

@spec struct(
  atom() | String.t(),
  keyword()
) :: RustQ.Rust.Struct.t()

to_fragment(item)

@spec to_fragment(term()) :: String.t()

trait(impl, trait)

type(value)

@spec type(rust_type()) :: String.t()

type(name, opts)

@spec type(atom() | String.t(), keyword() | [rust_type()]) :: String.t()

type_alias(name, type, opts \\ [])

@spec type_alias(atom() | String.t(), rust_type(), keyword()) ::
  RustQ.Rust.TypeAlias.t()

use(path, opts \\ [])

@spec use(
  term(),
  keyword()
) :: RustQ.Rust.Use.t()

use_many(paths, opts \\ [])

@spec use_many(
  [term()],
  keyword()
) :: [RustQ.Rust.Use.t()]

variant(item, variant)

variants(item, variants)

@spec variants(RustQ.Rust.EnumDecl.t(), [term()]) :: RustQ.Rust.EnumDecl.t()

vis(item, visibility)

@spec vis(term(), atom() | String.t() | nil) :: term()