use assert_matches::assert_matches; use build_deftly::prelude::*; use derive_deftly::Deftly; #[test] fn defaults() { #[derive(Deftly, Debug)] #[derive_deftly(Builder)] #[deftly(builder(build_fn(error = "HowImpolite")))] struct Hello { greetings: String, } #[derive(Debug)] struct HowImpolite(String); impl From for HowImpolite { fn from(_value: build_deftly::UninitializedFieldError) -> Self { HowImpolite("no greetingsā€½".into()) } } let s = Hello::builder().build(); assert_matches!(s, Err(HowImpolite(s)) if s == "no greetingsā€½"); let h = Hello::builder() .greetings("well done".into()) .build() .unwrap(); assert_eq!(&h.greetings, "well done"); }