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#![warn(missing_docs)]
11
12#[allow(unused_imports)]
13use proc_macro::TokenStream as BaseTokenStream;
14
15#[cfg(feature = "attr_parse")]
16mod attr_parse;
17
18/// Derive the `AttributeOptions` trait for a struct.
19///
20/// | Field options | |
21/// | ----- | ----- |
22/// | `#[attr_opts(rename = "new_ident")]` | Use this ident when parsing instead of the struct field's name |
23/// | `#[attr_opts(default = some_module::default_fn)]` | Use this function for the default value |
24/// | `#[attr_opts(default = false)]` | Make this option required and error if it isn't provided |
25///
26/// The alternative syntax is fine too, `#[attr_opts(default(false))]`
27#[cfg(feature = "attr_parse")]
28#[proc_macro_derive(AttributeOptions, attributes(attr_opts))]
29pub fn derive_attribute_options(input: BaseTokenStream) -> BaseTokenStream {
30 attr_parse::run::<attr_parse::AttrOptionsDerive>(input)
31}
32
33/// Derive the `ParseOption` trait for a struct. Uses the same field options as [`AttributeOptions`].
34///
35/// | Container Options | |
36/// | ----- | ----- |
37/// | `#[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` |
38#[cfg(feature = "attr_parse")]
39#[proc_macro_derive(ParseOption, attributes(attr_opts))]
40pub fn derive_parse_option(input: BaseTokenStream) -> BaseTokenStream {
41 attr_parse::run::<attr_parse::ParseOptionDerive>(input)
42}