gild 0.1.1

A simple validator library
Documentation
  • Coverage
  • 53.33%
    8 out of 15 items documented7 out of 13 items with examples
  • Size
  • Source code size: 12.28 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 462.36 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 14s Average build duration of successful builds.
  • all releases: 14s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Nickforall/Gild
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Nickforall

Gild

Gild is a simple validation library in Rust, you can chain multiple conditions and check whether the input is valid. You can also write your own validators, if our set of validator conditions isn't enough.

Using it is as easy as this:


ValidationChain::new()
    .add(validators::MaxSize::new(1)) // false
    .add(validators::MinSize::new(5)) // true
    .validate(String::from("Hello, World"))
    .is_ok();

Writing custom rules

We make use of Rust's great typesystem to create custom validators

struct MyCustomValidator;

impl ValidatorCondition for MyCustomValidator {
    fn validate(&self, input: String) -> bool {
        if input == String::from("cool") {
            return true
        }

        return false
    }

    fn get_err_message(&self) -> String {
        format!("Input is not cool...")
    }
}

If you wrote a validator that you think the community might want to use, feel free to open a PR

Validation rules

We currently have a small set of rules available:

  • MaxSize
  • MinSize
  • Contains
  • Empty
  • NotContains