{"id":19666569,"url":"https://github.com/tu6ge/valitron","last_synced_at":"2025-04-28T22:31:47.493Z","repository":{"id":189118653,"uuid":"680072584","full_name":"tu6ge/valitron","owner":"tu6ge","description":"Valitron is a rust validation, support ergonomics, functional and configurable","archived":false,"fork":false,"pushed_at":"2024-05-23T02:09:01.000Z","size":380,"stargazers_count":50,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-05-23T05:41:45.360Z","etag":null,"topics":["actix-web","axum","functional","rust-validator","validation","validator"],"latest_commit_sha":null,"homepage":"https://docs.rs/valitron","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tu6ge.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-18T09:20:44.000Z","updated_at":"2024-05-30T03:40:14.790Z","dependencies_parsed_at":"2024-04-24T07:39:21.628Z","dependency_job_id":"5ba0258c-b41d-4a47-ace1-0226a502bb1d","html_url":"https://github.com/tu6ge/valitron","commit_stats":null,"previous_names":["tu6ge/validator"],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tu6ge%2Fvalitron","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tu6ge%2Fvalitron/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tu6ge%2Fvalitron/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tu6ge%2Fvalitron/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tu6ge","download_url":"https://codeload.github.com/tu6ge/valitron/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251397643,"owners_count":21583045,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["actix-web","axum","functional","rust-validator","validation","validator"],"created_at":"2024-11-11T16:28:08.187Z","updated_at":"2025-04-28T22:31:44.391Z","avatar_url":"https://github.com/tu6ge.png","language":"Rust","funding_links":[],"categories":["Libraries"],"sub_categories":["Web programming"],"readme":"# Valitron is an ergonomic, functional and configurable validator\n\nIn the future, modularization will be supported\n\nInspired by axum\n\n## Features\n\n- Ergonomics validation\n- Build-in rule, e.g. Required, StartWith ...\n- Closure validate\n- Related validate, e.g. password confirm\n- Custom rule with other parameter\n- Check / modify input data\n- Custom error message type\n- Support different error types convert, it can use both build-in rules and custom error type simultaneously\n- Collect validate error messages\n- Support all types data on `#[derive(Serialize, Deserialize)]` ( visit [`serde`](https://serde.rs/) for more info)\n\n## Example 1\n\n```rust\nfn main() {\n    let validator = Validator::new()\n        .rule(\"name\", Required.and(StartWith(\"hello\")))\n        .rule(\"age\", custom(age_limit))\n        .message([\n            (\"name.required\", \"name is required\"),\n            (\"name.start_with\", \"name should be starts with `hello`\"),\n        ]);\n\n    let person = Person {\n        name: \"li\",\n        age: 18,\n    };\n\n    let res = validator.validate(person);\n    // or using trait\n    let res = person.validate(validator);\n}\n\nfn age_limit(n: \u0026mut u8) -\u003e Result\u003c(), Message\u003e {\n    if *n \u003e= 25 \u0026\u0026 *n \u003c= 45 {\n        return Ok(());\n    }\n    Err(\"age should be between 25 and 45\".into())\n}\n```\n## Example 2\n```rust\nuse valitron::register::string::Validator;\nimpl Input {\n    fn new(mut input: Input) -\u003e Result\u003cSelf, Validator\u003cMessage\u003e\u003e {\n        let valid = Validator::new()\n            .insert(\"name\", \u0026mut input.name, Trim.and(Required))\n            .insert(\"email\", \u0026mut input.email, Trim.and(Required).and(Email))\n            .insert(\"gender\", \u0026mut input.gender, custom(validate_gender))\n            .insert(\n                \"password\",\n                \u0026mut input.password,\n                Trim.custom(validate_password),\n            )\n            .insert_fn(\"age\", || {\n                if input.age \u003c 10 {\n                    input.age = 10;\n                }\n                if input.age \u003e 18 {\n                    Err(Message::fallback(\"age is out of range\"))\n                } else {\n                    Ok(())\n                }\n            });\n\n        valid.validate(input)\n    }\n}\nfn validate_password(pass: \u0026mut String) -\u003e Result\u003c(), Message\u003e {\n    todo!()\n}\n\nfn validate_gender(gender: \u0026mut String) -\u003e Result\u003c(), Message\u003e {\n    Ok(())\n}\n```\n\n[Document](https://docs.rs/valitron)\n\n## Rules Usage\n\n|Usage| Description|\n|---|--- |\n| `Required` | one rule |\n| `Required.and(StartsWith(\"foo\"))` | multi rules |\n| `Required.and(StartsWith('a')).bail()`| multi rules and bail|\n| `custom(my_handler)` | custom handler rule |\n| `Required.custom(my_handler)` | rule and handler rule |\n| `Not(StartsWith(\"foo\"))` | negative rule |\n| `Required.and(Not(StartsWith(\"foo\")))` | negative rule |\n\n## Bench\n| [second scheme](https://github.com/tu6ge/valitron/blob/string/examples/string.rs)| [validator](https://github.com/Keats/validator)(other library) |\n| --- | --- |\n| 192.55 ns | 680.43 ns |\n\n#### License\n\n\u003csup\u003e\nLicensed under either of \u003ca href=\"LICENSE-APACHE\"\u003eApache License, Version\n2.0\u003c/a\u003e or \u003ca href=\"LICENSE-MIT\"\u003eMIT license\u003c/a\u003e at your option.\n\u003c/sup\u003e\n\n\u003cbr\u003e\n\n\u003csub\u003e\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in this crate by you, as defined in the Apache-2.0 license, shall\nbe dual licensed as above, without any additional terms or conditions.\n\u003c/sub\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftu6ge%2Fvalitron","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftu6ge%2Fvalitron","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftu6ge%2Fvalitron/lists"}