Skip to main content

Crate attribute_dsl

Crate attribute_dsl 

Source
Expand description

§attribute-dsl

Build Status Codecov Docs Crates.io

attribute-dsl provides syn parsers for Rust proc-macro attributes built from a path root, ordered dot calls, optional labels, comma-separated entries, and named groups. It also supports rust-analyzer completion probes and _ placeholders for application-owned subject types.

Use it in derive-macro and attribute-macro implementation crates. The consumer keeps ownership of domain validation, constructors, and generated Rust.

§Quick start

Add the crate alongside the syn dependency used by the macro:

cargo add attribute-dsl

Parse an attribute chain through syn:

use attribute_dsl::{AttributeChain, ChainCompletion};

let chain: AttributeChain =
    syn::parse_str("RootType::<_>.first(1).second::<String>(\"value\")")
        .expect("valid attribute chain");

assert_eq!(
    chain
        .root_path()
        .segments
        .last()
        .expect("a parsed path has a segment")
        .ident
        .to_string(),
    "RootType"
);
assert_eq!(chain.calls().len(), 2);
assert!(matches!(chain.completion(), ChainCompletion::None));

The result retains syn::Path, syn::Ident, and syn::Expr nodes so the consumer can preserve syntax and spans while quoting its expansion.

§Capabilities

  • Parse one chain, a labeled entry, a list, or a named group.
  • Recover a trailing dot as a typed rust-analyzer completion probe.
  • Inspect or replace _ type placeholders in paths, types, and expressions.
  • Return syn::Error values for spanned proc-macro diagnostics.

§Documentation

Structs§

AttributeChain
A parsed Rust attribute expression made from a path root and zero or more dot calls.
ChainCall
One dot-call in an AttributeChain.
ChainEntry
A single chain entry, optionally labeled as label = Chain.
ChainList
A comma-separated list of ChainEntry values.
ChainParseOptions
Parser options for AttributeChain.
NamedChainGroup
A named parenthesized chain group such as each(Thing.a(1), other = Thing.b(2)).

Enums§

ChainCompletion
Completion state for a parsed chain.
CompletionProbeParsing
Whether completion-probe syntax is accepted while parsing a chain.
SingleTypeArg
Single terminal type argument split from a path.

Constants§

DEFAULT_COMPLETION_MARKER
The method name rust-analyzer should complete against after a trailing dot.

Functions§

split_terminal_single_type_arg
Split a path’s final generic argument into a normalized single type arg.
substitute_infer_in_expr
Substitute replacement for every _ occurrence inside an expression.
substitute_infer_in_path
Substitute replacement for every _ occurrence inside path arguments.
substitute_infer_in_type
Substitute replacement for every _ occurrence inside a type.