Module fog_pack::validator

source ·
Expand description

The fog-pack Validators, for building Schemas and Queries.

This submodule contains various validators, which can be transformed into the Validator enum type for use in a Schema or a Query. Each struct acts as a constructor that can be built into a Validator.

Validators are not used directly; instead, they should be used to build a Schema or Query, which will run them against fog-pack data.

There are validators for each fog-pack core type:

In addition to the core types, there are 4 special validators:

  • Validator::Ref - a reference to a validator stored in a schema’s map of types. Uses a name to look up the validator.
  • MultiValidator - Will attempt a sequence of validators, passing if any one of them pass.
  • EnumValidator - Acts as a validator for serialized Rust enums. This can also be implemented through MapValidator, but this validator is generally easier to use correctly in such cases.
  • Validator::Any - accepts any fog-pack value without examining it.

Examples

Say we want to build a Document that acts like a file directory. We want to store the creation time of the directory, and a list of file names with associated Hashes, each of which will be the Hash of a file or directory. Let’s also assume we want a valid Unix file name, meaning “/” and NUL cannot be in the name, it cannot be longer than 255 bytes, and shouldn’t be “.” or “..”. A validator for this Document might look like:

let dir = MapValidator::new()
    .req_add("created", TimeValidator::new().build())
    .req_add("contents", MapValidator::new()
        .keys(StrValidator::new()
            .nin_add(".")
            .nin_add("..")
            .ban_char("/\0")
            .max_len(255)
            .min_len(1)
        )
        .values(HashValidator::new().build())
        .build()
    )
    .build();

Structs

Enums