Crate fieldx_aux

Crate fieldx_aux 

Source
Expand description

Helper crate for fieldx and any third-party crates that extend its functionality. Can be used either to extend FieldX functionality or to implement your own proc-macros.

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"))1.
  • A set of types implementing standard fieldx arguments like helpers or literal values.

§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!

Read the FieldX Object Manager book for the introduction on how to use this crate.


  1. Here, the first argument of error()Error—is an enum, and SomeProblem is one of its variants. 

Re-exports§

pub use crate::accessor_helper::FXAccessorHelper;
pub use crate::accessor_helper::FXAccessorMode;
pub use crate::attributes::FXAttribute;
pub use crate::base_helper::FXBaseHelper;
pub use crate::builder_helper::FXBuilderHelper;
pub use crate::default_arg::FXDefault;
pub use crate::doc_arg::FXDocArg;
pub use crate::fallible::FXFallible;
pub use crate::nesting_attr::FXNestingAttr;
pub use crate::nesting_attr::FromNestAttr;
pub use crate::serde_helper::FXSerdeHelper;
pub use crate::setter_helper::FXSetterHelper;
pub use crate::syn_value::FXPunctuated;
pub use crate::syn_value::FXSynTupleArg;
pub use crate::syn_value::FXSynValueArg;
pub use crate::value::FXValueArg;
pub use crate::with_origin::FXOrig;
pub use crate::property::*;
pub use crate::traits::*;

Modules§

accessor_helper
Implementation of accessor helper (get argument of fxstruct/fieldx attributes).
attributes
attributes* family of arguments.
base_helper
The most basic helper declaration
builder_helper
Parameters of builder pattern and builder object.
default_arg
Default value.
doc_arg
fallible
Argument that signals possibility of errors.
nesting_attr
Argument nesting support module.
property
serde_helper
setter_helper
syn_value
Support for types that are not supported by darling but implement syn::parse::Parse
traits
value
Literal value arguments
with_origin
Trait for objects that know their origins.

Macros§

ident_or_alias
join_token_list
set_literals
Generate implementation of set_literals method for FromNestAttr trait.
to_tokens_vec
validate_exclusives
Generate validate_exclusives that would return a darling::Result if two arguments of an attribute are conflicting with each other.
validate_no_subarg_at_level
Generate code error out on sub-arguments that are invalid at a given level.

Structs§

FXSyncMode

Enums§

FXSyncModeVariant
Concurrency mode

Type Aliases§

FXAccessor
Accessor helper
FXAttributes
FXBool
Boolean literal
FXBuilder
Builder helper
FXDoc
doc argument
FXHelper
Standard helper
FXSerde
serde argument
FXSetter
Setter helper
FXString
String literal
FXSynTuple
Standard tuple for types implementing syn::parse::Parse
FXSynValue
Standard type implementing syn::parse::Parse
FXValue
Standard literal value

Attribute Macros§

fxhelper
This macro is used to generate helper structs. It adds the following fields to support related helper functionality: