Expand description
§attribute-dsl
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-dslParse 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::Errorvalues for spanned proc-macro diagnostics.
§Documentation
- Follow the attribute-dsl guide for parser selection, completion probes, infer substitution, and expansion patterns.
- Use the API documentation for public items and signatures.
Structs§
- Attribute
Chain - A parsed Rust attribute expression made from a path root and zero or more dot calls.
- Chain
Call - One dot-call in an
AttributeChain. - Chain
Entry - A single chain entry, optionally labeled as
label = Chain. - Chain
List - A comma-separated list of
ChainEntryvalues. - Chain
Parse Options - Parser options for
AttributeChain. - Named
Chain Group - A named parenthesized chain group such as
each(Thing.a(1), other = Thing.b(2)).
Enums§
- Chain
Completion - Completion state for a parsed chain.
- Completion
Probe Parsing - Whether completion-probe syntax is accepted while parsing a chain.
- Single
Type Arg - 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
replacementfor every_occurrence inside an expression. - substitute_
infer_ in_ path - Substitute
replacementfor every_occurrence inside path arguments. - substitute_
infer_ in_ type - Substitute
replacementfor every_occurrence inside a type.