Debian Codegraph @

third_party/rust/smart-default/examples/example.rs

raw
1 use smart_default::SmartDefault;
2
3 #[derive(PartialEq, SmartDefault, Debug)]
4 #[allow(dead_code)]
5 enum Foo {
6 Bar,
7 #[default]
8 Baz {
9 #[default(12)]
10 a: i32,
11 b: i32,
12 #[default(Some(Default::default()))]
13 c: Option<i32>,
14 #[default(_code = "vec![1, 2, 3]")]
15 d: Vec<u32>,
16 #[default = "four"]
17 e: String,
18 },
19 Qux(i32),
20 }
21
22 fn main() {
23 assert!(
24 Foo::default()
25 == Foo::Baz {
26 a: 12,
27 b: 0,
28 c: Some(0),
29 d: vec![1, 2, 3],
30 e: "four".to_owned(),
31 }
32 );
33 }