use core::marker::PhantomData;
use crate::intersection::{Intersection, check_intersection};
use crate::schubert_typed::SchubertTyped;
pub struct SchubertProven<M: SchubertTyped, T> {
value: T,
_marker: PhantomData<M>,
cached_type: crate::SchubertType,
}
impl<M: SchubertTyped, T> SchubertProven<M, T> {
pub fn new(value: T) -> Self {
Self {
value,
_marker: PhantomData,
cached_type: M::schubert_type(),
}
}
pub fn value(&self) -> &T {
&self.value
}
pub fn into_inner(self) -> T {
self.value
}
pub fn check_against<U: SchubertTyped>(&self) -> Option<Intersection> {
let other = U::schubert_type();
let result = check_intersection(&self.cached_type, &other);
if result.kind().is_zero() {
None
} else {
Some(result)
}
}
}
impl<M: SchubertTyped, T: core::fmt::Debug> core::fmt::Debug for SchubertProven<M, T> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("SchubertProven")
.field("value", &self.value)
.finish()
}
}
impl<M: SchubertTyped, T: Clone> Clone for SchubertProven<M, T> {
fn clone(&self) -> Self {
Self {
value: self.value.clone(),
_marker: PhantomData,
cached_type: self.cached_type.clone(),
}
}
}
impl<M: SchubertTyped, T: PartialEq> PartialEq for SchubertProven<M, T> {
fn eq(&self, other: &Self) -> bool {
self.value == other.value
}
}
impl<M: SchubertTyped, T: Eq> Eq for SchubertProven<M, T> {}
pub fn compose_checks<A: SchubertTyped, B: SchubertTyped, C: SchubertTyped>() -> Option<Intersection>
{
let a_type = A::schubert_type();
let b_type = B::schubert_type();
let c_type = C::schubert_type();
let ab = check_intersection(&a_type, &b_type);
if ab.kind().is_zero() {
return None;
}
let ab_c = check_intersection(&a_type, &c_type);
if ab_c.kind().is_zero() {
return None;
}
Some(ab_c)
}