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
//
// Original Copyright 2017 Idan Arye
// Modifications Copyright 2023 Signal Messenger, LLC.
// SPDX-License-Identifier: AGPL-3.0-only
//
use ;
/// Derive the `PartialDefault` trait.
///
/// The value used for a field can be overridden using the `#[partial_default(value =
/// "alternative()")]` syntax, where `alternative()` is a Rust expression that evaluates to the
/// correct type.
///
/// By default, the derived implementation will add a `T: PartialDefault` trait for every generic
/// parameter, like the built-in `derive(Default)`. You can override this by adding
/// `#[partial_default(bound = "T: MyTrait")]` to the type, which replaces any inferred bounds. Use
/// an empty string to impose no restrictions at all.
///
/// # Examples
///
/// ```
/// use partial_default::PartialDefault;
///
/// # fn main() {
/// #[derive(PartialDefault)]
/// #[partial_default(bound = "")]
/// # #[derive(PartialEq)]
/// # #[allow(dead_code)]
/// enum Foo<T> {
/// Bar,
/// #[partial_default]
/// Baz {
/// #[partial_default(value = "12")]
/// a: i32,
/// b: i32,
/// #[partial_default(value = "Some(Default::default())")]
/// c: Option<i32>,
/// #[partial_default(value = "vec![1, 2, 3]")]
/// d: Vec<u32>,
/// #[partial_default(value = r#""four".to_owned()"#)]
/// e: String,
/// },
/// Qux(T),
/// }
///
/// assert!(Foo::<&u8>::partial_default() == Foo::<&u8>::Baz {
/// a: 12,
/// b: 0,
/// c: Some(0),
/// d: vec![1, 2, 3],
/// e: "four".to_owned(),
/// });
/// # }
/// ```