Skip to main content

Crate tatara_rust_attr

Crate tatara_rust_attr 

Source
Expand description

tatara-rust-attr — typed attribute model + PerAttrDeriveSpec.

Two primitives:

  • AttrKnob — typed description of a consumer-side #[trait(key = …)] knob the derive understands. Each knob has a name + value-kind + optional default.
  • PerAttrDeriveSpec — derive shape that reads its knobs from the consumer’s #[<trait_name>(…)] attribute(s) and parameterizes its emission on the parsed values.

Today’s emit shape is the prefix-template family: a knob named prefix with a string default. The per-field template re-uses the prefix via #prefix. Sufficient for serde-style rename / derive- builder-style setter-prefix patterns.

Authoring shape:

use tatara_rust_ast::{CompileToCrate, Ident};
use tatara_rust_attr::{AttrKnob, AttrValueKind, PerAttrDeriveSpec};

let spec = PerAttrDeriveSpec {
    trait_name: Ident::new("Prefixed"),
    knobs: vec![AttrKnob {
        name: "prefix".into(),
        kind: AttrValueKind::Str,
        default: Some("with_".into()),
    }],
    per_field_template:
        "pub fn #prefix #field_name(self, v: #field_ty) -> Self { self }".into(),
};
let scaffold = spec.compile_to_crate("prefixed-derive").unwrap();
assert!(scaffold.to_files().contains_key("src/lib.rs"));

Structs§

AttrKnob
PerAttrDeriveSpec

Enums§

AttrValueKind