Skip to main content

Module validate

Module validate 

Source
Available on crate feature validate only.
Expand description

Garde rules every declared schema shares. A repository’s config and a template’s own exports are held to the same rules and report the same messages.

Each one is a #[garde(custom(…))] rule. It runs at the boundary, on a fully parsed value, and garde names the field that failed. The rules are generic over the context. The same rule works in a schema validated against nothing and in one validated against the whole document.

use ctl_core::validate::{at_least_one, one_file_name};

assert!(one_file_name::<()>("notes.md", &()).is_ok());
assert!(one_file_name::<()>("docs/notes.md", &()).is_err());
assert!(at_least_one::<String, ()>("label")(&[], &()).is_err());

Functions§

at_least_one
A rule for a list that must not be empty. The noun names what the list holds, in the message: at_least_one("label") reports “must declare at least one label”.
cannot_be_empty
A rule for a string that must not be empty. The because text gives the reason, so the message explains itself.
inside_the_repo
A path a repository may write to: relative, and never upward out of the tree.
one_file_name
One file name, so a name cannot smuggle in the path it was separated from.