use struct_update::Struct; #[derive(Debug)] struct B { f3: i64, f4: &'static str, } #[derive(Debug)] struct C { f5: u64, } #[derive(Debug)] struct A { f1: i32, f2: &'static str, f3: i64, f4: &'static str, f5: u64, } #[test] fn basic() { let b = B { f3: 5, f4: "tt" }; let c = C { f5: 7 }; let a = Struct! {A, f1: 3 + 5, f2: "sss", [f3,f4,]: ..b, [f5]: ..c, }; dbg!(&a); assert_eq!(a.f1, 8); assert_eq!(a.f2, "sss"); assert_eq!(a.f3, 5); assert_eq!(a.f4, "tt"); assert_eq!(a.f5, 7); } mod mm { #[derive(Debug)] pub struct A2 { pub f1: i32, pub f2: &'static str, pub f3: i64, pub f4: &'static str, pub f5: u64, } } #[test] fn path() { let b = B { f3: 5, f4: "tt" }; let c = C { f5: 7 }; let a = Struct! {mm::A2, f1: 3 + 5, f2: "sss", [f3,f4,]: ..b, [f5]: ..c, }; dbg!(&a); assert_eq!(a.f1, 8); assert_eq!(a.f2, "sss"); assert_eq!(a.f3, 5); assert_eq!(a.f4, "tt"); assert_eq!(a.f5, 7); let a = Struct! {mm::A2, f1: 3 + 5, [f3,f4,]: ..b, [f5]: ..c, f2: "sss", }; dbg!(&a); assert_eq!(a.f1, 8); assert_eq!(a.f2, "sss"); assert_eq!(a.f3, 5); assert_eq!(a.f4, "tt"); assert_eq!(a.f5, 7); } #[test] fn path_as() { let b = B { f3: 5, f4: "tt" }; let c = C { f5: 7 }; let a = Struct! {mm::A2 as A, [f3,f4,]: ..b, f2: "sss", [f5]: ..c, f1: 3 + 5, }; dbg!(&a); assert_eq!(a.f1, 8); assert_eq!(a.f2, "sss"); assert_eq!(a.f3, 5); assert_eq!(a.f4, "tt"); assert_eq!(a.f5, 7); }