use crate::resolve::EdgeOrData;
pub trait DataWellformedness<'sg, DATA> {
type Output;
fn data_wf(&self, data: &'sg DATA) -> Self::Output;
}
impl<'sg, DATA: 'sg, T, O: 'sg> DataWellformedness<'sg, DATA> for T
where
T: Fn(&'sg DATA) -> O,
{
type Output = O;
fn data_wf(&self, data: &'sg DATA) -> O {
self(data)
}
}
#[derive(Default)]
pub struct DefaultDataWellformedness {}
impl<'sg, DATA> DataWellformedness<'sg, DATA> for DefaultDataWellformedness {
type Output = bool;
fn data_wf(&self, _data: &'sg DATA) -> bool {
true }
}
pub trait LabelOrder<LABEL> {
fn less_than(&self, l1: &EdgeOrData<LABEL>, l2: &EdgeOrData<LABEL>) -> bool;
}
impl<LABEL, T> LabelOrder<LABEL> for T
where
T: for<'a, 'b> Fn(&'a EdgeOrData<LABEL>, &'b EdgeOrData<LABEL>) -> bool,
{
fn less_than(&self, l1: &EdgeOrData<LABEL>, l2: &EdgeOrData<LABEL>) -> bool {
self(l1, l2)
}
}
#[derive(Default)]
pub struct DefaultLabelOrder {}
impl<LABEL> LabelOrder<LABEL> for DefaultLabelOrder {
fn less_than(&self, _l1: &EdgeOrData<LABEL>, _l2: &EdgeOrData<LABEL>) -> bool {
false }
}
pub trait DataEquivalence<'sg, DATA> {
type Output;
fn data_equiv(&self, d1: &'sg DATA, d2: &'sg DATA) -> Self::Output;
fn always_equivalent(&self) -> bool {
false
}
}
impl<'sg, DATA: 'sg, T, O: 'sg> DataEquivalence<'sg, DATA> for T
where
T: Fn(&'sg DATA, &'sg DATA) -> O,
{
type Output = O;
fn data_equiv(&self, d1: &'sg DATA, d2: &'sg DATA) -> Self::Output {
self(d1, d2)
}
}
#[derive(Default)]
pub struct DefaultDataEquivalence {}
impl<'sg, DATA> DataEquivalence<'sg, DATA> for DefaultDataEquivalence {
type Output = bool;
fn data_equiv(&self, _d1: &'sg DATA, _d2: &'sg DATA) -> bool {
true }
fn always_equivalent(&self) -> bool {
true
}
}