gdp_rs 0.0.3

A library for implementing Ghosts-of-departed-proofs pattern in rust
Documentation
use std::marker::PhantomData;

use crate::{proposition::Proposition, proven::Proven};

/// A struct representing a conditional proposition
/// that is conditional over another proposition.
#[allow(clippy::type_complexity)]
pub struct Conditional<S, C, A> {
    _phantom: PhantomData<fn(S) -> Result<(), (C, A)>>,
}

impl<S, C, A> Clone for Conditional<S, C, A> {
    fn clone(&self) -> Self {
        Self {
            _phantom: self._phantom,
        }
    }
}

impl<S, C, A> std::fmt::Debug for Conditional<S, C, A> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("AllOf").finish()
    }
}

impl<S, C, A> Proposition<S> for Conditional<S, C, A>
where
    C: Proposition<S>,
    A: Proposition<S>,
{
}

impl<S, C, A> Proven<S, Conditional<S, C, A>>
where
    C: Proposition<S>,
    A: Proposition<S>,
{
    /// Conditionalize already proven proposition.
    //
    // Safety: If consequence is always true, then it must be true if CPA is true.
    #[inline]
    pub fn from_proven(v: Proven<S, C>) -> Self {
        unsafe { Self::new_unchecked(v.into_subject()) }
    }

    /// Promise that condition i conditional proposition holds,
    /// and convert to consequence proven proposition.
    ///
    /// # Safety
    ///
    /// Callers must promise that CPA (conditional proof assumption) holds.
    #[inline]
    pub unsafe fn promise_condition(self) -> Proven<S, C> {
        Proven::new_unchecked(self.into_subject())
    }
}