#builder #serde #dependency-injection #lazy-evaluation #thread-safe

fieldx_aux

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

13 releases

new 0.1.16 Apr 30, 2025
0.1.12 Mar 21, 2025
0.1.8 Dec 5, 2024
0.1.7 Nov 22, 2024

#400 in Procedural macros

Download history 5/week @ 2025-01-08 137/week @ 2025-01-15 2/week @ 2025-01-29 15/week @ 2025-02-05 256/week @ 2025-02-12 426/week @ 2025-02-19 27/week @ 2025-02-26 4/week @ 2025-03-05 3/week @ 2025-03-12 249/week @ 2025-03-19 25/week @ 2025-03-26 7/week @ 2025-04-02 1/week @ 2025-04-09 588/week @ 2025-04-16 372/week @ 2025-04-23

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

Custom license

94KB
2.5K SLoC

fieldx_aux

Helper crate for fieldx and any third-party crates that extend its functionality.

fieldx is heavily based on the darling crate, which greatly simplifies proc-macro development, but also imposes some constraints on attribute argument syntax. This crate overcomes these limitations and provides support for attribute kinds required to implement fieldx.

Here is a brief breakdown of what is provided:

  • Support for nested arguments, i.e. those that look like arg1("value", trigger, subarg(...)).
  • Support for syntax elements not covered by the darling crate, such as some_type(crate::types::Foo) and error(crate::error::Error, crate::error::Error::SomeProblem("with details"))[^tuple].
  • A set of types implementing standard fieldx arguments like helpers or literal values.

[^tuple]: Here, the first argument of error()Error—is an enum, and SomeProblem is one of its variants.

Usage

Imagine we are implementing a field-level attribute foo using the darling::FromField trait, and we want it to accept the following arguments:

  • trigger: enables or disables certain functionality
  • action: specifies a method with special meaning
  • comment: accepts arbitrary text
  • vis: indicates whether field-related code should be public, and if so, which kind of pub modifier to use

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

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

For this, you'll need the following declaration somewhere in your proc-macro implementation:

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

    trigger: Option<FXBool>,
    action: Option<FXHelper>,
    comment: Option<FXString>,
    vis: Option<FXSynValue<syn::Visibility>>,
}

That's all; this crate will take care of implementing the arguments for you!

Dependencies

~0.6–1MB
~23K SLoC