mod ground;
mod iri;
mod matcher;
mod partial;
pub use ground::{
SchemaFreeGroundEntailment, SchemaFreeGroundError, SchemaFreeGroundLimits,
SchemaFreeGroundOutcome, SchemaFreeGroundReport, SchemaFreeGroundRestriction,
};
pub use iri::IriTermAccess;
pub use matcher::SimpleEntailment;
pub(crate) use partial::PartialMatches;
use serde::{Deserialize, Serialize};
use std::{
error::Error,
fmt,
future::Future,
num::{NonZeroU32, NonZeroU64},
};
pub trait EntailmentTerms: Send + Sync {
type Term: Clone + Eq + Send + Sync;
type Error: Error + Send + Sync + 'static;
fn is_blank(&self, term: &Self::Term)
-> impl Future<Output = Result<bool, Self::Error>> + Send;
fn triple_term(
&self,
term: &Self::Term,
) -> impl Future<Output = Result<Option<[Self::Term; 3]>, Self::Error>> + Send;
fn is_cancelled(&self) -> bool;
}
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct EntailmentLimits {
patterns: NonZeroU32,
bindings: NonZeroU32,
terms: NonZeroU32,
steps: NonZeroU64,
}
impl EntailmentLimits {
pub const fn new(
patterns: NonZeroU32,
bindings: NonZeroU32,
terms: NonZeroU32,
steps: NonZeroU64,
) -> Self {
Self {
patterns,
bindings,
terms,
steps,
}
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct EntailmentReport {
pub entailed: bool,
pub target_triples: u32,
pub steps: u64,
}
#[derive(Debug)]
pub enum EntailmentError<E> {
Storage(E),
Cancelled,
TargetLimit,
BindingLimit,
TermLimit,
StepLimit,
}
impl<E: fmt::Display> fmt::Display for EntailmentError<E> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Storage(error) => write!(f, "entailment storage failed: {error}"),
Self::Cancelled => f.write_str("entailment cancelled"),
Self::TargetLimit => f.write_str("entailment target limit exceeded"),
Self::BindingLimit => f.write_str("entailment bindings limit exceeded"),
Self::TermLimit => f.write_str("entailment term worklist limit exceeded"),
Self::StepLimit => f.write_str("entailment steps limit exceeded"),
}
}
}
impl<E: Error + 'static> Error for EntailmentError<E> {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
Self::Storage(error) => Some(error),
_ => None,
}
}
}