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