#[repr(transparent)]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct ValidationScope(u8);
impl ValidationScope {
pub const EMPTY: Self = Self(0);
pub const FINITE: Self = Self(0b0000_0001);
pub const PROBLEM_CONFIG: Self = Self(0b0000_0010);
pub const PRELOOP: Self = Self(0b0000_0100);
pub const ALL: Self = Self(Self::FINITE.0 | Self::PROBLEM_CONFIG.0 | Self::PRELOOP.0);
pub const fn empty() -> Self {
Self::EMPTY
}
pub const fn contains(self, other: Self) -> bool {
(self.0 & other.0) == other.0
}
pub const fn union(self, other: Self) -> Self {
Self(self.0 | other.0)
}
pub const fn intersect(self, other: Self) -> Self {
Self(self.0 & other.0)
}
}
impl core::ops::BitOr for ValidationScope {
type Output = Self;
fn bitor(self, rhs: Self) -> Self {
self.union(rhs)
}
}
impl core::ops::BitAnd for ValidationScope {
type Output = Self;
fn bitand(self, rhs: Self) -> Self {
self.intersect(rhs)
}
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum FiniteCoverage {
Checked,
NotApplicable,
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum TrustKind {
CallerAssertion,
}
#[repr(transparent)]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct TrustToken(u32);
impl TrustToken {
pub const fn new(value: u32) -> Self {
Self(value)
}
pub const fn value(self) -> u32 {
self.0
}
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct ValidationCoverage {
scope: ValidationScope,
finite: FiniteCoverage,
}
impl ValidationCoverage {
pub const fn new(scope: ValidationScope, finite: FiniteCoverage) -> Self {
Self {
scope: scope.union(ValidationScope::FINITE),
finite,
}
}
pub const fn scope(self) -> ValidationScope {
self.scope
}
pub const fn finite(self) -> FiniteCoverage {
self.finite
}
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct TrustedByCaller {
pub scope: ValidationScope,
pub kind: TrustKind,
pub token: TrustToken,
pub label: Option<&'static str>,
}
impl TrustedByCaller {
pub const fn caller_assertion(
scope: ValidationScope,
token: TrustToken,
label: Option<&'static str>,
) -> Self {
Self {
scope,
kind: TrustKind::CallerAssertion,
token,
label,
}
}
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum ValidationState {
Unvalidated,
Validated(ValidationCoverage),
Trusted(TrustedByCaller),
}
#[cfg(test)]
mod tests;