#![cfg(test)] #![allow(unused)] use default_variant::default; #[default(Baz { one: 1, two: 2 })] enum MyStruct1 { Foo, Bar, Baz { one: usize, two: u32 }, } #[default( Foo { foo: { let mut arr = [None; 3]; arr[0] = Some(true); arr } } )] enum MyStruct2 { Foo { foo: [Option; 3] }, Bar, } #[default( Quux { a: Default::default() } where A: Default )] enum MyGenericStruct1 { Foo, Bar, Baz, Quux { a: A }, } #[default( Foo { int: 15, pair: Default::default() } where A: Default, B: Default )] enum MyGenericStruct2 { Foo { int: usize, pair: (A, B) }, Bar, } #[test] fn struct_variant_default() { assert!(matches!( MyStruct1::default(), MyStruct1::Baz { one: 1, two: 2 } )); } #[test] fn generic_struct_variant_default() { assert!(matches!( MyGenericStruct1::default(), MyGenericStruct1::Quux { a: false } )); assert!(matches!( MyGenericStruct1::default(), MyGenericStruct1::Quux { a: 0 } )); assert!(matches!( MyGenericStruct1::default(), MyGenericStruct1::Quux { a: Option::::None } )); } #[test] fn generic_struct_with_bounds_variant_default() { assert!(matches!( MyGenericStruct2::default(), MyGenericStruct2::Foo { int: 15, pair: ( MyStruct2::Foo { foo: [Some(true), None, None] }, MyStruct1::Baz { one: 1, two: 2 } ) } )); }