#![allow(dead_code)] use mogrify::{MogrificationError, Mogrify}; use std::collections::HashMap; struct RawInput { name: String, maybe_foo: Option, missing_foo: Option, items: Vec, map: HashMap, } #[derive(Eq, PartialEq, Hash)] struct StringWrap(String); impl TryFrom for StringWrap { type Error = MogrificationError; fn try_from(value: String) -> Result { if &value == "error" { Err(MogrificationError::new("invalid string")) } else { Ok(StringWrap(value)) } } } #[derive(Mogrify)] #[mogrify(RawInput)] struct MogrifiedInput { name: StringWrap, #[mogrify(require)] maybe_foo: StringWrap, missing_foo: Option, items: Vec, map: HashMap, } fn main() { let raw = RawInput { name: "".to_string(), maybe_foo: None, missing_foo: None, items: vec![], map: HashMap::new(), }; let _: Result = raw.try_into(); }