use std::ops::{Neg, Not};
use std::cmp::{PartialOrd, PartialEq};
#[derive(Debug, Clone)]
pub struct Secret<E, T> {
pub evidence: Option<E>,
pub value: T,
}
impl<E, T> Neg for Secret<E, T>
where T: Neg
{
type Output = Secret<E, T::Output>;
fn neg(self) -> Secret<E, T::Output> {
Secret {value: -self.value, evidence: self.evidence}
}
}
impl<E> Not for Secret<E, bool> {
type Output = Secret<E, bool>;
fn not(self) -> Secret<E, bool> {
Secret {value: !self.value, evidence: self.evidence}
}
}
impl<E, T> Secret<E, T> {
pub fn lt<U>(self, other: &U) -> Secret<E, bool>
where T: PartialOrd<U>
{
Secret {
value: self.value.lt(other),
evidence: self.evidence
}
}
pub fn le<U>(self, other: &U) -> Secret<E, bool>
where T: PartialOrd<U>
{
Secret {
value: self.value.le(other),
evidence: self.evidence
}
}
pub fn gt<U>(self, other: &U) -> Secret<E, bool>
where T: PartialOrd<U>
{
Secret {
value: self.value.gt(other),
evidence: self.evidence
}
}
pub fn ge<U>(self, other: &U) -> Secret<E, bool>
where T: PartialOrd<U>
{
Secret {
value: self.value.ge(other),
evidence: self.evidence
}
}
pub fn eq<U>(self, other: &U) -> Secret<E, bool>
where T: PartialEq<U>
{
Secret {
value: self.value.eq(other),
evidence: self.evidence
}
}
pub fn ne<U>(self, other: &U) -> Secret<E, bool>
where T: PartialEq<U>
{
Secret {
value: self.value.ne(other),
evidence: self.evidence
}
}
}