use std::{borrow::Borrow, marker::PhantomData, ops::Deref};
use crate::proposition::{Evaluable, Proposition};
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Proven<S, P> {
subject: S,
_gdp: PhantomData<P>,
}
impl<S, P> AsRef<S> for Proven<S, P> {
#[inline]
fn as_ref(&self) -> &S {
&self.subject
}
}
impl<S, P> Deref for Proven<S, P> {
type Target = S;
#[inline]
fn deref(&self) -> &Self::Target {
&self.subject
}
}
impl<S, P> Borrow<S> for Proven<S, P> {
#[inline]
fn borrow(&self) -> &S {
&self.subject
}
}
impl<S, P> Proven<S, P>
where
P: Proposition<S>,
{
#[inline]
pub fn into_subject(self) -> S {
self.subject
}
#[inline]
pub unsafe fn new_unchecked(subject: S) -> Self {
Self {
subject,
_gdp: PhantomData,
}
}
}
impl<S, P> Proven<S, P>
where
P: Proposition<S> + Evaluable<S>,
{
pub fn try_new(subject: S) -> Result<Self, P::EvalError> {
P::evaluate_for(&subject).map(|_| Self {
subject,
_gdp: PhantomData,
})
}
}