RustQ.Syn.Index (rustq v0.6.0)

Copy Markdown View Source

In-memory index of Rust source metadata parsed by RustQ.Syn.

Use an index when a generator needs to query many Rust files without keeping project-specific source maps. The index stores parsed files by path and offers lookup helpers for impl blocks and methods by target type.

It also indexes Rust use items and type aliases. Generators can inspect them directly with uses/1 and type_aliases/1, or ask for the public Rust name that exposes a native/bindings type with public_type_name/2 and public_type_name!/2. Reexport chains such as pub use paint::Cap as PaintCap; are followed so callers can prefer the crate's public API surface over internal module names.

Summary

Functions

Returns a cached index for all Rust sources in a Cargo package.

Clears a cached package index.

Fetches an enum by name.

Fetches an enum by name, raising if missing.

Returns all indexed top-level enums.

Builds an index for all Rust sources in a Cargo package.

Builds an index from Rust source file paths.

Returns all indexed top-level impl blocks.

Returns impl blocks whose target type matches target.

Fetches a method from impl blocks matching target.

Fetches a method from impl blocks matching target, raising if missing.

Returns all methods from impl blocks matching target.

Finds the public Rust type name that aliases a target Rust type name.

Finds the public Rust type name that aliases a target Rust type name, raising if missing.

Fetches a top-level type alias by name.

Fetches a top-level type alias by name, raising if missing.

Returns all indexed top-level type aliases.

Fetches a top-level use alias by alias name.

Fetches a top-level use alias by alias name, raising if missing.

Returns all indexed top-level use aliases.

Types

t()

@type t() :: %RustQ.Syn.Index{
  files: %{required(Path.t()) => RustQ.Syn.File.t()},
  package: RustQ.Cargo.Package.t() | nil
}

Functions

cached_package(package_name, opts \\ [])

@spec cached_package(
  String.t(),
  keyword()
) :: t()

Returns a cached index for all Rust sources in a Cargo package.

clear_cached_package(package_name, opts \\ [])

@spec clear_cached_package(
  String.t(),
  keyword()
) :: :ok

Clears a cached package index.

enum(index, name)

@spec enum(t(), String.t()) :: {:ok, RustQ.Syn.Enum.t()} | :error

Fetches an enum by name.

enum!(index, name)

@spec enum!(t(), String.t()) :: RustQ.Syn.Enum.t()

Fetches an enum by name, raising if missing.

enums(index)

@spec enums(t()) :: [RustQ.Syn.Enum.t()]

Returns all indexed top-level enums.

from_package(package_name, opts \\ [])

@spec from_package(
  String.t(),
  keyword()
) :: t()

Builds an index for all Rust sources in a Cargo package.

from_paths(paths, opts \\ [])

@spec from_paths(
  [Path.t()],
  keyword()
) :: t()

Builds an index from Rust source file paths.

impls(index)

@spec impls(t()) :: [RustQ.Syn.Impl.t()]

Returns all indexed top-level impl blocks.

impls(index, target)

@spec impls(t(), String.t()) :: [RustQ.Syn.Impl.t()]

Returns impl blocks whose target type matches target.

method(index, target, name)

@spec method(t(), String.t(), String.t()) :: {:ok, RustQ.Syn.Method.t()} | :error

Fetches a method from impl blocks matching target.

method!(index, target, name)

@spec method!(t(), String.t(), String.t()) :: RustQ.Syn.Method.t()

Fetches a method from impl blocks matching target, raising if missing.

methods(index, target)

@spec methods(t(), String.t()) :: [RustQ.Syn.Method.t()]

Returns all methods from impl blocks matching target.

public_type_name(index, target)

@spec public_type_name(t(), String.t()) :: {:ok, String.t()} | :error

Finds the public Rust type name that aliases a target Rust type name.

public_type_name!(index, target)

@spec public_type_name!(t(), String.t()) :: String.t()

Finds the public Rust type name that aliases a target Rust type name, raising if missing.

type_alias(index, name)

@spec type_alias(t(), String.t()) :: {:ok, RustQ.Syn.TypeAlias.t()} | :error

Fetches a top-level type alias by name.

type_alias!(index, name)

@spec type_alias!(t(), String.t()) :: RustQ.Syn.TypeAlias.t()

Fetches a top-level type alias by name, raising if missing.

type_aliases(index)

@spec type_aliases(t()) :: [RustQ.Syn.TypeAlias.t()]

Returns all indexed top-level type aliases.

use_alias(index, alias)

@spec use_alias(t(), String.t()) :: {:ok, RustQ.Syn.Use.t()} | :error

Fetches a top-level use alias by alias name.

use_alias!(index, alias)

@spec use_alias!(t(), String.t()) :: RustQ.Syn.Use.t()

Fetches a top-level use alias by alias name, raising if missing.

uses(index)

@spec uses(t()) :: [RustQ.Syn.Use.t()]

Returns all indexed top-level use aliases.