smart_config_derive/lib.rs
1//! Procedural macros for `smart-config`.
2//!
3//! All macros in this crate are re-exported from the `smart-config` crate. See its docs for more details
4//! and the examples of usage.
5//!
6//! - [Macro reference](../../smart_config/_docs/derive_ref/) <!-- x-release-please-version -->
7//! - [Examples of usage](../../smart_config/_docs/derive_examples/) <!-- x-release-please-version -->
8
9// Documentation settings
10#![doc(html_root_url = "https://docs.rs/smart-config-derive/0.4.0-pre.2")] // x-release-please-version
11// General settings
12#![recursion_limit = "128"]
13
14extern crate proc_macro;
15
16use proc_macro::TokenStream;
17
18mod de;
19mod describe;
20mod example;
21mod utils;
22
23/// Derives the `DescribeConfig` trait for a type. Typically used together with [`DeserializeConfig`]
24/// to generate a fully deserializable, self-descriptive configuration.
25///
26/// # See also
27///
28/// - [Macro reference](../../smart_config/_docs/derive_ref/) <!-- x-release-please-version -->
29/// - [Examples of usage](../../smart_config/_docs/derive_examples/) <!-- x-release-please-version -->
30#[proc_macro_derive(DescribeConfig, attributes(config))]
31pub fn describe_config(input: TokenStream) -> TokenStream {
32 describe::impl_describe_config(input)
33}
34
35/// Derives the `ExampleConfig` trait for a type. This allows to provide an example for all config parameters.
36///
37/// This macro is intended to be used together with [`DescribeConfig`]; it reuses
38/// the same attributes. Specifically, for each config field, the default value is assigned from the following sources
39/// in the decreasing priority order:
40///
41/// 1. `example`
42/// 2. `default` / `default_t`, including implied ones for `Option`al fields
43/// 3. From `ExampleConfig` implementation (only for nested / flattened configs)
44///
45/// # See also
46///
47/// - [Macro reference](../../smart_config/_docs/derive_ref/) <!-- x-release-please-version -->
48/// - [Examples of usage](../../smart_config/_docs/derive_examples/) <!-- x-release-please-version -->
49#[proc_macro_derive(ExampleConfig, attributes(config))]
50pub fn example_config(input: TokenStream) -> TokenStream {
51 example::impl_example_config(input)
52}
53
54/// Derives the `DeserializeConfig` trait for a type. Typically used together with [`DescribeConfig`]
55/// to generate a fully deserializable, self-descriptive configuration.
56///
57/// # See also
58///
59/// - [Macro reference](../../smart_config/_docs/derive_ref/) <!-- x-release-please-version -->
60/// - [Examples of usage](../../smart_config/_docs/derive_examples/) <!-- x-release-please-version -->
61#[proc_macro_derive(DeserializeConfig, attributes(config))]
62pub fn deserialize_config(input: TokenStream) -> TokenStream {
63 de::impl_deserialize_config(input)
64}