ical/valid.rs
1//! # Validity proof
2//!
3//! [`IcalValid`], the marker a check mints and nothing else can.
4//!
5//! Validity is a runtime predicate in this crate, never a second, stricter
6//! type: a conformant calendar may still carry extensions, so a no-extension
7//! type would name a useless category. What a type *can* carry is the proof
8//! that a check ran and passed, which is what this is. It is a plain wrapper
9//! with a private field, so the only way to hold one is to have been handed it
10//! by a validator.
11//!
12//! Two validators mint it today, and they live at opposite ends of the crate:
13//! [`Ical::validate`](crate::ical::Ical::validate) over a whole calendar, and
14//! [`IcalRecurRule::validate`](crate::recur::IcalRecurRule::validate) over one
15//! recurrence rule. The marker is here, in the dependency-free core, so neither
16//! has to depend on the other's feature to speak the same language.
17
18use core::ops;
19
20/// A value that passed its validator. Only a validator can mint one, so holding
21/// it is proof of conformance.
22#[derive(Clone, Copy, Debug, PartialEq, Eq)]
23pub struct IcalValid<T>(pub(crate) T);
24
25impl<T> IcalValid<T> {
26 /// Unwrap the validated value.
27 pub fn into_inner(self) -> T {
28 self.0
29 }
30}
31
32impl<T> ops::Deref for IcalValid<T> {
33 type Target = T;
34
35 fn deref(&self) -> &Self::Target {
36 &self.0
37 }
38}