1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//! # `fancy-default`
//!
//! This library provides enhancements to the standard library's `Default` derive macro.
//!
//! 
//! 
//! 
//!
//! ## Table of Contents
//!
//! - [Generic default value configuration](#generic-default-value-configuration)
//! - [the `Default` macro](#fancy_defaultderivedefault)
//! - [the `ConstDefault` macro](#fancy_defaultderiveconstdefault)
//! - [the `VariantDefault` macro](#fancy_defaultderivevariantdefault)
//! - [License & MSRV](#msrv)
//!
//! ## Generic default value configuration
//!
//! All default value configurations in this library use the same syntax.
//!
//! - Field configuration:
//! - `#[default]`: Calls `core::default::Default` and uses it as the default value.
//!
//! **Note**: Currently `core::default::Default` is not a constant trait,
//! so a default value must be specified when using `ConstDefault`.
//! - `#[default = <expr>]`: Use `<expr>` as the default value for this field.
//!
//! **Note**: `better_default` does not use string literals to parse expressions,
//! so you can write expressions with default values directly,
//! like: `#[default = "foobar".to_owned()]`.
//! - `#[default(expr = <expr>)]`: Same meaning as the previous format.
//! - Variant configuration(enum only):
//! - `#[default]`: Set the variant as the default variant of the enum.
//! This attribute works the same as the standard library's `#[default]`.
//!
//! ## `fancy_default::derive::Default`
//!
//! **Basic Usage:**
//!
//! ```rust
//! use fancy_default::Default;
//!
//! #[derive(Debug, Default, PartialEq, Eq)]
//! struct Person {
//! #[default(expr = "no-name".to_owned())]
//! name: String,
//! #[default]
//! id: usize,
//! #[default(expr = Some("unknown".to_owned()))]
//! tag: Option<String>,
//! }
//!
//! assert_eq!(
//! Person::default(),
//! Person {
//! name: "no-name".to_owned(),
//! id: 0,
//! tag: Some("unknown".to_owned()),
//! }
//! );
//! ```
//!
//! ## `fancy_default::derive::ConstDefault`
//!
//! **Basic Usage:**
//!
//! ```rust
//! // this imports both `fancy_default::derive::ConstDefault`
//! // and `fancy_default::traits::ConstDefault`.
//! use fancy_default::ConstDefault;
//!
//! #[derive(Debug, ConstDefault, PartialEq, Eq)]
//! struct Person<'a> {
//! #[default = "no-name"]
//! name: &'a str,
//! #[default = 0]
//! id: usize,
//! #[default(expr = Some("unknown"))]
//! tag: Option<&'a str>,
//! }
//!
//! assert_eq!(
//! Person::DEFAULT,
//! Person {
//! name: "no-name",
//! id: 0,
//! tag: Some("unknown"),
//! }
//! );
//! ```
//!
//! ## `fancy_default::derive::VariantDefault`
//!
//! Set default values for each variant of the enumeration.This derive macro uses an additional attribute `variant`, to set how the default value are generated.
//!
//! **Config Syntax:**
//!
//! - `#[variant(<config>)]`:
//! - `const`/`const = <bool>`: Whether to generate constant default values.
//! The corresponding constant name is the UPPER_CASE version of the current enumeration.
//! Default: `false`.
//! Alias: `constant`.
//! - `func`/`func = <bool>`: Whether to generate static methods that return default values.
//! The corresponding constant name is the snake_case version of the current enumeration and has a `default_` prefix.
//! Default: `true`.
//! Alias: `fn`, `function`.
//!
//! **Note:** This attribute can be added to an enum body or to a single variant.
//! If added to the enum body, it will override the default generated configuration.
//!
//! **Basic Usage:**
//!
//! ```rust
//! use fancy_default::VariantDefault;
//!
//! #[derive(Debug, VariantDefault, PartialEq, Eq)]
//! #[variant(const)]
//! enum Enum {
//! Plain,
//! #[variant(const = false)]
//! Struct {
//! #[default(expr = "123".to_owned())]
//! name: String,
//! },
//! Tuple(#[default = 10] usize),
//! }
//!
//!
//! assert_eq!(Enum::PLAIN, Enum::Plain);
//! assert_eq!(
//! Enum::default_struct(),
//! Enum::Struct {
//! name: "123".to_owned()
//! }
//! );
//! ```
//!
//! ## MSRV
//!
//! The theoretical minimum rust version of this derived macro is 1.34,
//! which allows passing `TokenStream` to `MetaList` from that version onwards.
//!
//! ## License
//!
//! This library is licensed under the MIT license or the Apache v2.0 license.
/// Derive macros provided by the library.
/// `Default`-like traits implemented by the derive macros.
pub use ;
pub use ConstDefault;