#proc-macro #struct #builder #lazy-evaluation #field #macro #builder-pattern

fieldx_aux

Various types and tools useful for fieldx crates and, potentially, to users of fieldx

5 releases

new 0.1.8 Dec 5, 2024
0.1.7 Nov 22, 2024
0.1.6 Oct 19, 2024
0.1.5 Oct 3, 2024
0.1.3 Aug 2, 2024

#353 in Procedural macros

Download history 1/week @ 2024-08-17 4/week @ 2024-08-24 9/week @ 2024-08-31 16/week @ 2024-09-14 14/week @ 2024-09-21 459/week @ 2024-09-28 411/week @ 2024-10-05 52/week @ 2024-10-12 733/week @ 2024-10-19 17/week @ 2024-10-26 14/week @ 2024-11-02 2/week @ 2024-11-09 124/week @ 2024-11-16 59/week @ 2024-11-23 355/week @ 2024-11-30

543 downloads per month
Used in 4 crates (3 directly)

Custom license

62KB
1.5K SLoC

Helper module for the fieldx crate and for any 3rd party crates, extending fieldx functionality.

fieldx itself is heavily based on darling crate which simplifies development of proc-macros quite a lot. But it also imposes some constrains on attribute arguments syntax. This crate aims at overcoming these limitations and providing support for some kinds of attributes required to implement fieldx.

Here is a little break down of what is provided:

  • support for nested arguments, i.e. those that look like param1("value", trigger, subarg(...))
  • support for some syntax elements that are not on the darling crate menu: some_type(crate::types::Foo), error(crate::error::Error, crate::error::Error::SomeProblem("with details"))[^tuple]
  • a set of types implementing standard fieldx arguments like helpers, or literal values, etc.

[^tuple]: Here Error is an enum, SomeProblem is a variant.

Usage

Let's say we're implementing a field-level attribute foo using darling::FromField trait. And we want it to take these arguments:

  • trigger which would let turn some functionality on or off
  • action to specify a method with special meaning
  • comment with some text
  • public to specify if field-related code must be public and if yes then what kind of pub we need

A field declaration may take the following form with the attribute:

    #[foo(
        trigger,
        action("method_name", private),
        comment("Whatever we consider useful."),
        public(crate)
    )]
    bar: usize,

For this we'd need the following declaration somewhere in our proc-macro implementation:

#derive(FromField)
#[darling(attributes(foo))]
struct FooField {
    // ... skipping some darling-default fields ...

    trigger: Option<FXBool>,
    action: Option<FXHelper>,
    comment: Option<FXString>,
    public: Option<FXNestingAttr<FXPubMode>>,
}

That's all, this crate will take the burden of implementing the arguments from you!

Dependencies

~0.6–1MB
~24K SLoC