Skip to main content

Module validator

Module validator 

Source
Expand description

§Validator

The strict half of “liberal in, strict out”, as a runtime predicate rather than a second data model.

Validity and lossiness are orthogonal: a conformant calendar may still carry extensions (unknown components, properties, parameters and value kinds), so “valid” cannot be a type with no Unknown arms.

Ical::validate therefore walks the whole component tree and checks its known parts against the per-property IcalPropSpec and per-component IcalComponentSpec for the calendar version, leaving the unknown parts alone. It reports:

  • a property the version does not define;
  • a value of a kind the property does not take;
  • a parameter the property does not take;
  • a property that appears more often than it may;
  • a property a component requires but does not carry (a VEVENT needs UID and DTSTAMP, a VALARM needs ACTION and TRIGGER, …);
  • a component nested where it may not be;
  • a recurrence rule that breaks RFC 5545 3.3.10.

A passing check mints an IcalValid marker, the only way to obtain one, so holding an IcalValid<Ical> is proof the check passed. The same per-property check backs the IcalPropBuilder’s strict construction.

§Example

Decode a parsed calendar, validate it into a proof, and convert that back into a byte tree:

use ical::tree::cst::IcalCst;

let raw = "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//x//EN\r\nEND:VCALENDAR\r\n";
let cst = IcalCst::parse(raw).unwrap();

// validate consumes the calendar and returns the proof (or the violations).
let valid = cst.decode().validate().expect("a conformant 2.0 calendar");

// The proof converts back into a byte tree for free.
let out = IcalCst::from(valid);
assert!(out.to_string().contains("PRODID:-//x//EN"));

Structs§

IcalValid
A value that passed its validator. Only a validator can mint one, so holding it is proof of conformance.

Enums§

IcalValidateError
A single conformance failure found by Ical::validate.