Skip to main content

wist_validate/
lib.rs

1//! Static validators for contracts, config, and runtime state.
2
3pub mod action_plan;
4pub mod action_result;
5pub mod config;
6pub mod gateway;
7pub mod state;
8
9use time::OffsetDateTime;
10use time::format_description::well_known::Rfc3339;
11
12#[derive(Debug, Clone, PartialEq, Eq)]
13pub struct ValidationError {
14    pub code: &'static str,
15}
16
17impl ValidationError {
18    pub const fn new(code: &'static str) -> Self {
19        Self { code }
20    }
21}
22
23pub(crate) fn require_non_empty(value: &str, code: &'static str) -> Result<(), ValidationError> {
24    if value.trim().is_empty() {
25        return Err(ValidationError::new(code));
26    }
27    Ok(())
28}
29
30pub(crate) fn parse_rfc3339(
31    value: &str,
32    code: &'static str,
33) -> Result<OffsetDateTime, ValidationError> {
34    OffsetDateTime::parse(value, &Rfc3339).map_err(|_| ValidationError::new(code))
35}