use relax::{Relax, Relaxed}; #[derive(Relax)] #[relax(PartialThing)] pub struct Thing { pub id: String, pub name: T, pub favorite: Option, } #[test] fn basic() { let mut partial_thing = PartialThing::::new(); partial_thing.id = Some("id".to_owned()); partial_thing.name = Some("name".to_owned()); let thing: Thing = partial_thing.try_into().unwrap(); assert_eq!(thing.id, "id"); assert_eq!(thing.name, "name"); assert!(thing.favorite.is_none()); } #[test] fn merge() { let mut partial_thing_1 = PartialThing::::new(); let mut partial_thing_2 = PartialThing::::new(); partial_thing_1.id = Some("id_1".to_owned()); partial_thing_1.favorite = Some(42); partial_thing_2.id = Some("id_2".to_owned()); partial_thing_2.name = Some("name_2".to_owned()); let thing: Thing = partial_thing_1.merge(partial_thing_2).try_into().unwrap(); assert_eq!(thing.id, "id_1"); assert_eq!(thing.name, "name_2"); assert_eq!(thing.favorite.unwrap(), 42); }