pub struct ValidationRule {
pub logic: Value,
pub message: Template,
pub compiled_logic: Option<Arc<Logic>>,
}Expand description
A single validation rule with a condition and error message.
The rule’s logic is evaluated against the message context. If it does not
return exactly true, the validation fails and the error message is recorded.
Fields§
§logic: ValueJSONLogic expression that must evaluate to true for validation to pass.
Any other result (false, null, etc.) is considered a validation failure.
message: TemplateError message to display if validation fails.
Required when a rule is deserialized as part of a workflow definition —
which is the path Engine::build takes, so a rule without it is
rejected at build time. ValidationConfig::from_json, the standalone
parser, is the one path that substitutes "Validation failed".
JSONLogic, so a message can name the value that failed:
{"cat": ["age must be positive, got ", {"var": "data.age"}]}. A plain
string is a literal, so the static spelling is unchanged.
Evaluated only when the rule fails, so a passing validation — the common case — costs nothing for a computed message.
This message is recorded in Message::errors, which is serialized, so
it may not read a secret. Engine::build refuses one that does; see
crate::IssueCode::SecretInMessageWrite.
compiled_logic: Option<Arc<Logic>>Pre-compiled JSONLogic, populated by LogicCompiler. None is
recorded as a COMPILATION_ERROR at execute time.
Trait Implementations§
Source§impl Clone for ValidationRule
impl Clone for ValidationRule
Source§fn clone(&self) -> ValidationRule
fn clone(&self) -> ValidationRule
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more