macroific_macro/lib.rs
1//! Proc macros for the [macroific](https://docs.rs/macroific) crate.
2
3#![deny(clippy::correctness, clippy::suspicious)]
4#![warn(clippy::complexity, clippy::perf, clippy::style, clippy::pedantic)]
5#![allow(
6 clippy::module_name_repetitions,
7 clippy::wildcard_imports,
8 clippy::uninlined_format_args
9)]
10#![cfg_attr(doc_cfg, feature(doc_auto_cfg))]
11#![warn(missing_docs)]
12
13#[allow(unused_imports)]
14use proc_macro::TokenStream as BaseTokenStream;
15
16#[cfg(feature = "attr_parse")]
17mod attr_parse;
18
19/// Derive the `AttributeOptions` trait for a struct.
20///
21/// | Field options | |
22/// | ----- | ----- |
23/// | `#[attr_opts(rename = "new_ident")]` | Use this ident when parsing instead of the struct field's name |
24/// | `#[attr_opts(default = some_module::default_fn)]` | Use this function for the default value |
25/// | `#[attr_opts(default = false)]` | Make this option required and error if it isn't provided |
26///
27/// The alternative syntax is fine too, `#[attr_opts(default(false))]`
28#[cfg(feature = "attr_parse")]
29#[proc_macro_derive(AttributeOptions, attributes(attr_opts))]
30pub fn derive_attribute_options(input: BaseTokenStream) -> BaseTokenStream {
31 attr_parse::run::<attr_parse::AttrOptionsDerive>(input)
32}
33
34/// Derive the `ParseOption` trait for a struct. Uses the same field options as [`AttributeOptions`].
35///
36/// | Container Options | |
37/// | ----- | ----- |
38/// | `#[attr_opts(from_parse)]` | Call [`Parse::parse`](::syn::parse::Parse::parse) to implement `ParseOption`. `Parse` will also get implemented if this option is omitted or `false` |
39#[cfg(feature = "attr_parse")]
40#[proc_macro_derive(ParseOption, attributes(attr_opts))]
41pub fn derive_parse_option(input: BaseTokenStream) -> BaseTokenStream {
42 attr_parse::run::<attr_parse::ParseOptionDerive>(input)
43}