Skip to content

fix: enhance nested validation to support absolute path in struct#386

Open
qyuzh wants to merge 1 commit intoKeats:masterfrom
qyuzh:master
Open

fix: enhance nested validation to support absolute path in struct#386
qyuzh wants to merge 1 commit intoKeats:masterfrom
qyuzh:master

Conversation

@qyuzh
Copy link

@qyuzh qyuzh commented Oct 14, 2025

Sometimes, we may want to use like this, but it fails compile for now

/// Sometimes users may want to use absolute path on struct, and validate in other module
pub mod test_nest_field_with_absolute_path {
    #[derive(validator::Validate)] // absolute path
    struct Parent {
        #[validate(nested)]
        child: Child,
        #[validate(nested)]
        child2: Child,
    }

    #[derive(validator::Validate)]
    struct Child {
        #[validate(length(min = 1))]
        value: String,
    }

    #[test]
    fn test() {
        use validator::Validate;
        let instance = Parent {
            child: Child { value: String::from("1") },
            child2: Child { value: String::from("2") },
        };
        assert!(instance.validate().is_ok());
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant