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
/// Generate `impl Default` for a struct created by [`schema!`](crate::schema!).
///
/// Every listed field is set to **its type's** `Default::default()` — the same
/// as `#[derive(Default)]`. Schema defaults (`.with_default(...)`) are **not**
/// used; to get them, parse an empty object instead:
/// `Config::parse_value(&serde_json::json!({}))`.
///
/// # Example
///
/// ```
/// use vld::prelude::*;
///
/// vld::schema! {
/// #[derive(Debug)]
/// pub struct Config {
/// pub host: String => vld::string().with_default("localhost".into()),
/// pub port: Option<i64> => vld::number().int().optional(),
/// pub tags: Vec<String> => vld::array(vld::string()).with_default(vec![]),
/// }
/// }
///
/// vld::impl_default!(Config { host, port, tags });
///
/// let cfg = Config::default();
/// assert_eq!(cfg.host, ""); // String::default(), NOT the schema default
/// assert_eq!(cfg.port, None); // Option::default()
/// assert!(cfg.tags.is_empty()); // Vec::default()
///
/// // Schema defaults come from parsing:
/// let parsed = Config::parse_value(&serde_json::json!({})).unwrap();
/// assert_eq!(parsed.host, "localhost");
/// ```