use rdf_types::Triple;
mod view;
pub use view::*;
pub trait Graph {
type Subject;
type Predicate;
type Object;
type Triples<'a>: Iterator<
Item = Triple<&'a Self::Subject, &'a Self::Predicate, &'a Self::Object>,
> where
Self: 'a;
type Subjects<'a>: Iterator<Item = (&'a Self::Subject, Self::Predicates<'a>)>
where
Self: 'a;
type Predicates<'a>: Iterator<Item = (&'a Self::Predicate, Self::Objects<'a>)>
where
Self: 'a;
type Objects<'a>: Iterator<Item = &'a Self::Object>
where
Self: 'a;
type PatternMatching<'a, 'p>: Iterator<
Item = Triple<&'a Self::Subject, &'a Self::Predicate, &'a Self::Object>,
> where
Self: 'a,
Self::Subject: 'p,
Self::Predicate: 'p,
Self::Object: 'p;
fn len(&self) -> usize;
fn is_empty(&self) -> bool {
self.len() == 0
}
fn triples(&self) -> Self::Triples<'_>;
fn subjects(&self) -> Self::Subjects<'_>;
fn predicates(&self, subject: &Self::Subject) -> Self::Predicates<'_>;
fn objects(&self, subject: &Self::Subject, predicate: &Self::Predicate) -> Self::Objects<'_>;
fn contains(&self, triple: Triple<&Self::Subject, &Self::Predicate, &Self::Object>) -> bool;
#[allow(clippy::type_complexity)]
fn pattern_matching<'p>(
&self,
pattern: Triple<
Option<&'p Self::Subject>,
Option<&'p Self::Predicate>,
Option<&'p Self::Object>,
>,
) -> Self::PatternMatching<'_, 'p>;
#[allow(clippy::type_complexity)]
fn any_match(
&self,
pattern: Triple<Option<&Self::Subject>, Option<&Self::Predicate>, Option<&Self::Object>>,
) -> Option<Triple<&Self::Subject, &Self::Predicate, &Self::Object>> {
self.pattern_matching(pattern).next()
}
fn view<'a, A>(&'a self, subject: &'a Self::Subject, access: A) -> GraphView<Self, A> {
GraphView::new(self, subject, access)
}
}
pub trait SizedGraph: Graph + Sized {
type IntoTriples: Iterator<
Item = Triple<
<Self as Graph>::Subject,
<Self as Graph>::Predicate,
<Self as Graph>::Object,
>,
>;
type IntoSubjects: Iterator<Item = (<Self as Graph>::Subject, Self::IntoPredicates)>;
type IntoPredicates: Iterator<Item = (<Self as Graph>::Predicate, Self::IntoObjects)>;
type IntoObjects: Iterator<Item = <Self as Graph>::Object>;
fn into_triples(self) -> Self::IntoTriples;
fn into_subjects(self) -> Self::IntoSubjects;
fn into_predicates(self, subject: &<Self as Graph>::Subject) -> Self::IntoPredicates;
fn into_objects(
self,
subject: &<Self as Graph>::Subject,
predicate: &<Self as Graph>::Predicate,
) -> Self::IntoObjects;
}
pub trait MutableGraph: Graph {
fn insert(
&mut self,
triple: Triple<
<Self as Graph>::Subject,
<Self as Graph>::Predicate,
<Self as Graph>::Object,
>,
) -> bool;
fn remove(
&mut self,
triple: Triple<
&<Self as Graph>::Subject,
&<Self as Graph>::Predicate,
&<Self as Graph>::Object,
>,
);
fn absorb<
G: SizedGraph<
Subject = <Self as Graph>::Subject,
Predicate = <Self as Graph>::Predicate,
Object = <Self as Graph>::Object,
>,
>(
&mut self,
other: G,
);
}
pub trait GraphTake<
T: ?Sized = <Self as Graph>::Subject,
U: ?Sized = <Self as Graph>::Predicate,
V: ?Sized = <Self as Graph>::Object,
>: Graph
{
#[allow(clippy::type_complexity)]
fn take(
&mut self,
triple: Triple<&T, &U, &V>,
) -> Option<Triple<Self::Subject, Self::Predicate, Self::Object>>;
#[allow(clippy::type_complexity)]
fn take_match(
&mut self,
triple: Triple<Option<&T>, Option<&U>, Option<&V>>,
) -> Option<Triple<Self::Subject, Self::Predicate, Self::Object>>;
}