{"id":15018052,"url":"https://github.com/chrisbuchholz/accord","last_synced_at":"2025-10-23T15:30:16.723Z","repository":{"id":57478919,"uuid":"78418531","full_name":"ChrisBuchholz/accord","owner":"ChrisBuchholz","description":"Data validation library for Rust","archived":false,"fork":false,"pushed_at":"2018-07-17T18:12:30.000Z","size":54,"stargazers_count":79,"open_issues_count":9,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-01-30T19:04:54.915Z","etag":null,"topics":["crates","json","library","rocket","rust","serde"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ChrisBuchholz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-09T10:27:02.000Z","updated_at":"2025-01-06T18:02:08.000Z","dependencies_parsed_at":"2022-09-17T04:21:55.363Z","dependency_job_id":null,"html_url":"https://github.com/ChrisBuchholz/accord","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChrisBuchholz%2Faccord","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChrisBuchholz%2Faccord/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChrisBuchholz%2Faccord/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChrisBuchholz%2Faccord/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ChrisBuchholz","download_url":"https://codeload.github.com/ChrisBuchholz/accord/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237843724,"owners_count":19375192,"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":["crates","json","library","rocket","rust","serde"],"created_at":"2024-09-24T19:51:22.303Z","updated_at":"2025-10-23T15:30:16.329Z","avatar_url":"https://github.com/ChrisBuchholz.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Accord\n\n[![Build Status](https://travis-ci.org/ChrisBuchholz/accord.svg?branch=master)](https://travis-ci.org/ChrisBuchholz/accord)\n[![Current Crates.io Version](https://img.shields.io/crates/v/accord.svg)](https://crates.io/crates/accord)\n[![API Documentation](https://docs.rs/accord/badge.svg)](https://docs.rs/accord)\n[![codecov](https://codecov.io/gh/ChrisBuchholz/accord/branch/master/graph/badge.svg)](https://codecov.io/gh/ChrisBuchholz/accord)\n\n[contribute]: #Contributing\n[conservative_impl_trait]: https://github.com/rust-lang/rfcs/blob/master/text/1522-conservative-impl-trait.md\n\nAccord is a library for validating data according to rules like *length*, *contains*, *range* and *either*.\n\nAccord is two fold, the first part being a set of validator-functions that\nfor example tests that a `String` has a minimum of 5 characters or that an `i32`\nis either *10* or *20*, and the second part being the `rules!` macro which allows you\nto run a set of validators on a single piece of data, or a whole collection of data\nand get back a set of errors which explains exactly what is wrong. The errors can\neasily be serialized using [Serde] and then be used in for example a REST API to\nreport to the user which of the data the user posted contains illegal values.\n\nSee the [Rocket example] for how to use Accord with [Rocket] to validate JSON input\nand return explanations for any occuring error as JSON which then can be\nparsed by the requesting application and shown to the user to guide them in\nhow to fix their input values according to the applications rules.\n\nError messages uses numbered placeholders meaning that an error message could\nbe *\"Must not be less than %1.\"* with an accompanien list `[5]`, which makes\nit easy to translate *\"Must not be less than %1.\"* without having to deal with the\nvariable value *5*.\n\n[Serde]: https://serde.rs\n[Rocket]: https://rocket.rs\n[Rocket example]: https://github.com/ChrisBuchholz/accord/tree/master/examples/unstable/rocket\n\n## Usage tl;dr:\n\n```rust\n#[macro_use]\nextern crate accord;\nextern crate serde;\nextern crate serde_json;\n\nuse accord::{Accord, Result as AccordResult, Error, MultipleError, MultipleInvalid};\nuse accord::validators::{length, contains, range};\n\nstruct Account {\n    pub name: String,\n    pub email: String,\n    pub age: i8,\n}\n\nimpl Accord for Account {\n    fn validate(\u0026self) -\u003e AccordResult {\n        rules!{\n            \"name\" =\u003e self.name =\u003e [length(1, 64)],\n            \"email\" =\u003e self.email =\u003e [length(5, 64), contains(\"@\"), contains(\".\")],\n            \"age\" =\u003e self.age =\u003e [range(12, 127)]\n        }\n    }\n}\n\nfn main() {\n    let account = Account {\n        name: \"\".to_string(),\n        email: \"test\".to_string(),\n        age: 11,\n    };\n\n    // You can use the `rules!` macro on any value.\n    // This way of using the the `rules!` macro returns a\n    // `Result\u003c(), Error\u003e`.\n    let _ = rules!(account.name, [length(1, 64)]);\n    let _ = rules!(account.email, [length(5, 64), contains(\"@\"), contains(\".\")]);\n    let _ = rules!(account.age, [range(12, 127)]);\n\n    // You can also use the collection form of the `rules!` macro\n    // again using any value you'd like.\n    // This way of using the `rules!` macro returns a\n    // `Result\u003c(), MultipleError\u003e`. Notice the string slices that has\n    // been appended to the lines from last example. These string slices\n    // are called tags and are used to distingues between the sets of errors\n    // that are returned.\n    let _ = rules!{\n        \"name\" =\u003e account.name =\u003e [length(1, 64)],\n        \"email\" =\u003e account.email =\u003e [length(5, 64), contains(\"@\"), contains(\".\")],\n        \"age\" =\u003e account.age =\u003e [range(12, 127)]\n    };\n\n    // And finally, since our `Account` has implemented the\n    // `Accord` trait, we can simply do the following, which once\n    // again returns `Result\u003c(), MultipleError\u003e`, which we then\n    // serialize to JSON using Serde and print:\n    if let Err(multiple_error) = account.validate() {\n        println!(\"Errors as json: {}\",\n                 serde_json::to_string(\u0026multiple_error).unwrap());\n    } else {\n        println!(\"No errors occured\");\n    }\n}\n```\n\n## Documentation\n\n* [Examples]: Usage examples are available in the *examples/* directory\n* [API Documentation]: Documentation generated from the source code, comments and examples\n\n[examples]: https://github.com/ChrisBuchholz/accord/tree/master/examples\n[API Documentation]: https://docs.rs/accord\n\n## Building locally\n\n### Stable\n\nBuilding: `cargo build`\n\nTesting: `cargo test`\n\n### Nightly + unstable features\n\nMake sure you have an up-to-date version of rust nightly installed.\n\nBuilding: `cargo build`\n\nTesting: `cargo test`\n\nYou can add `--features FEATURES TO ENABLE` to both `cargo build` and `cargo test` to build or test unstable features. The unstable features currently supported are:\n\n* `inclusive_range` [RFC#1192] which enables one to use the `length` and `range` validators with [inclusive ranges] instead of `a, b`-variables, as in the example above. An example crate using inclusive ranges can be found [here][inclusive_range_example].\n\n[RFC#1192]: https://github.com/rust-lang/rfcs/blob/master/text/1192-inclusive-ranges.md\n[inclusive ranges]: https://doc.rust-lang.org/std/ops/enum.RangeInclusive.html\n[inclusive_range_example]: https://github.com/ChrisBuchholz/accord/tree/master/examples/unstable/json\n\n### Make\n\nYou can also use [make] for doing more stuff in a simpler way. The Makefile\nrequires that you are using Rust via [rustup].\n\n[make]: https://www.gnu.org/software/make/\n[rustup]: https://www.rustup.rs\n\n* `make` will build and test Accord and all examples on both stable and nightly, on nightly both with and without unstable features\n* `make build` will build everything on both stable and nightly\n* `make build-stable` will build everything on stable\n* `make build-unstable` will build everything on nightly with and without unstable features\n* `make build-examples` will build examples on both stable and nightly\n* `make build-stable-examples`\n* `make build-unstable-examples`\n* `make build-stable-example-\u003cNAME-OF-STABLE-EXAMPLE\u003e`\n* `make build-unstable-example-\u003cNAME-OF-UNSTABLE-EXAMPLE\u003e`\n* `make test` will test everything on both stable and nightly, on nightly with and without unstable features\n* `make test-stable` will test everything on stable\n* `make test-unstable` will test everything on nightly with and without unstable features\n* `make test-examples` will test examples on both stable and nightly\n* `make test-stable-examples`\n* `make test-unstable-examples`\n* `make test-stable-example-\u003cNAME-OF-STABLE-EXAMPLE\u003e`\n* `make test-unstable-example-\u003cNAME-OF-UNSTABLE-EXAMPLE\u003e`\n\n## Contributing\n\nContributions are absolutely, positively welcome and encouraged! Contributions\ncome in many forms. You could:\n\n1. Submit a feature request or bug report as an [issue][issues].\n2. Ask for improved documentation as an [issue][issues].\n3. Contribute code via [pull requests][pulls].\n\n[issues]: https://github.com/ChrisBuchholz/accord/issues\n[pulls]: https://github.com/ChrisBuchholz/accord/pulls\n\nTo keep a high standard of quality, contributed code must be:\n\n  * **Commented:** Public items _must_ be commented.\n  * **Documented:** Exposed items _must_ have rustdoc comments with\n    examples, if applicable.\n  * **Styled:** Your code should be `rustfmt`'d when possible.\n  * **Simple:** Your code should accomplish its task as simply and\n     idiomatically as possible.\n  * **Tested:** You must add (and pass) convincing tests for any functionality you add.\n  * **Focused:** Your code should do what it's supposed to do and nothing more.\n\nAll pull requests are code reviewed and tested by the CI. Note that unless you\nexplicitly state otherwise, any contribution intentionally submitted for\ninclusion in Accord by you shall be MIT License without any additional terms or conditions.\n\n*Thanks to [Rocket][rocket-contrib] for showing how to form a great contributing-section.*\n\n[rocket-contrib]: https://github.com/SergioBenitez/Rocket/blob/master/README.md#contributing\n\n## License\n\nAccord is Copyright (c) 2017 Christoffer Buchholz. It is free software, and\nmay be redistributed under the terms specified in the [LICENSE] file.\n\n[LICENSE]: /LICENSE\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrisbuchholz%2Faccord","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchrisbuchholz%2Faccord","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrisbuchholz%2Faccord/lists"}