Keats / validator

Simple validation for Rust structs
MIT License
1.97k stars 141 forks source link

Setting code to be string from ENUM #273

Open 0xDjole opened 11 months ago

0xDjole commented 11 months ago
pub struct CategoryCreatePayload {
    #[validate(length(min = 1, code = CategoryError::NotFound(String::from("HERE").to_string())))]
    pub name: String,
    #[validate(length(min = 1, code = "400.41"))]
    pub parent_id: Option<String>,
    pub tenant_id: String,
    #[validate(length(min = 1, code = "400.42"))]
    pub policies: Vec<PolicyCreatePayload>,
}

I'd like to use string from enums as a code and not a hardcoded string. #[validate(length(min = 1, code = CategoryError::NotFound(String::from("HERE").to_string())))]

Like this