pub use rdf_types::{Quad, Triple};
mod graph;
mod r#impl;
pub mod macros;
pub mod utils;
mod view;
#[cfg(feature = "meta")]
pub mod meta;
pub use graph::*;
pub use r#impl::*;
pub use view::*;
pub trait Dataset {
type Subject;
type Predicate;
type Object;
type GraphLabel;
type Graph: Graph<Subject = Self::Subject, Predicate = Self::Predicate, Object = Self::Object>;
type Graphs<'a>: Iterator<Item = (Option<&'a Self::GraphLabel>, &'a Self::Graph)>
where
Self: 'a;
type Quads<'a>: Iterator<
Item = Quad<&'a Self::Subject, &'a Self::Predicate, &'a Self::Object, &'a Self::GraphLabel>,
> where
Self: 'a;
type PatternMatching<'a, 'p>: Iterator<
Item = Quad<&'a Self::Subject, &'a Self::Predicate, &'a Self::Object, &'a Self::GraphLabel>,
> where
Self: 'a,
Self::Subject: 'p,
Self::Predicate: 'p,
Self::Object: 'p,
Self::GraphLabel: 'p;
fn graph(&self, id: Option<&Self::GraphLabel>) -> Option<&Self::Graph>;
fn default_graph(&self) -> &Self::Graph {
self.graph(None).unwrap()
}
fn graphs(&self) -> Self::Graphs<'_>;
fn quads(&self) -> Self::Quads<'_>;
fn len(&self) -> usize {
let mut len = 0;
for (_, g) in self.graphs() {
len += g.len()
}
len
}
fn is_empty(&self) -> bool {
for (_, g) in self.graphs() {
if !g.is_empty() {
return false;
}
}
true
}
fn subjects<'a>(
&'a self,
id: Option<&Self::GraphLabel>,
) -> Option<<Self::Graph as Graph>::Subjects<'a>>
where
Self::Graph: 'a,
Self::Subject: 'a,
Self::Predicate: 'a,
Self::Object: 'a,
{
self.graph(id).map(|graph| graph.subjects())
}
fn view<'a, A>(
&'a self,
graph_label: Option<&'a Self::GraphLabel>,
subject: &'a Self::Subject,
access: A,
) -> View<Self, A> {
View::new(self, graph_label, self.graph(graph_label), subject, access)
}
fn predicates<'a>(
&'a self,
id: Option<&Self::GraphLabel>,
subject: &Self::Subject,
) -> Option<<Self::Graph as Graph>::Predicates<'a>>
where
Self::Graph: 'a,
Self::Predicate: 'a,
Self::Object: 'a,
{
self.graph(id).map(|graph| graph.predicates(subject))
}
fn objects<'a>(
&'a self,
id: Option<&Self::GraphLabel>,
subject: &Self::Subject,
predicate: &Self::Predicate,
) -> Option<<Self::Graph as Graph>::Objects<'a>>
where
Self::Graph: 'a,
Self::Object: 'a,
{
self.graph(id)
.map(|graph| graph.objects(subject, predicate))
}
#[allow(clippy::type_complexity)]
fn contains(
&self,
Quad(s, p, o, g): Quad<&Self::Subject, &Self::Predicate, &Self::Object, &Self::GraphLabel>,
) -> bool {
match self.graph(g) {
Some(g) => g.contains(Triple(s, p, o)),
None => false,
}
}
#[allow(clippy::type_complexity)]
fn pattern_matching<'p>(
&self,
pattern: Quad<
Option<&'p Self::Subject>,
Option<&'p Self::Predicate>,
Option<&'p Self::Object>,
Option<&'p Self::GraphLabel>,
>,
) -> Self::PatternMatching<'_, 'p>;
#[allow(clippy::type_complexity)]
fn any_match(
&self,
pattern: Quad<
Option<&Self::Subject>,
Option<&Self::Predicate>,
Option<&Self::Object>,
Option<&Self::GraphLabel>,
>,
) -> Option<Quad<&Self::Subject, &Self::Predicate, &Self::Object, &Self::GraphLabel>> {
self.pattern_matching(pattern).next()
}
#[allow(clippy::type_complexity)]
#[deprecated = "use `any_match` instead"]
fn first_match(
&self,
pattern: Quad<
Option<&Self::Subject>,
Option<&Self::Predicate>,
Option<&Self::Object>,
Option<&Self::GraphLabel>,
>,
) -> Option<Quad<&Self::Subject, &Self::Predicate, &Self::Object, &Self::GraphLabel>> {
self.any_match(pattern)
}
}
pub trait SizedDataset: Dataset + Sized
where
Self::Graph: SizedGraph,
{
type IntoGraphs: Iterator<Item = (Option<Self::GraphLabel>, Self::Graph)>;
type IntoQuads: Iterator<
Item = Quad<Self::Subject, Self::Predicate, Self::Object, Self::GraphLabel>,
>;
fn into_graph(self, id: Option<&Self::GraphLabel>) -> Option<Self::Graph>;
fn into_default_graph(self) -> Self::Graph {
self.into_graph(None).unwrap()
}
fn into_graphs(self) -> Self::IntoGraphs;
fn into_quads(self) -> Self::IntoQuads;
fn into_subjects(
self,
id: Option<&Self::GraphLabel>,
) -> Option<<Self::Graph as SizedGraph>::IntoSubjects> {
self.into_graph(id).map(|graph| graph.into_subjects())
}
fn into_predicates(
self,
id: Option<&Self::GraphLabel>,
subject: &Self::Subject,
) -> Option<<Self::Graph as SizedGraph>::IntoPredicates> {
self.into_graph(id)
.map(|graph| graph.into_predicates(subject))
}
fn into_objects(
self,
id: Option<&Self::GraphLabel>,
subject: &Self::Subject,
predicate: &Self::Predicate,
) -> Option<<Self::Graph as SizedGraph>::IntoObjects> {
self.into_graph(id)
.map(|graph| graph.into_objects(subject, predicate))
}
}
pub trait MutableDataset: Dataset {
type GraphsMut<'a>: Iterator<Item = (Option<&'a Self::GraphLabel>, &'a mut Self::Graph)>
where
Self: 'a;
fn graph_mut(&mut self, id: Option<&Self::GraphLabel>) -> Option<&mut Self::Graph>;
fn default_graph_mut(&mut self) -> &mut Self::Graph {
self.graph_mut(None).unwrap()
}
fn graphs_mut(&mut self) -> Self::GraphsMut<'_>;
fn insert_graph(&mut self, id: Self::GraphLabel, graph: Self::Graph) -> Option<Self::Graph>;
fn insert(
&mut self,
quad: Quad<Self::Subject, Self::Predicate, Self::Object, Self::GraphLabel>,
) -> bool;
fn remove(
&mut self,
quad: Quad<&Self::Subject, &Self::Predicate, &Self::Object, &Self::GraphLabel>,
);
fn absorb<
D: SizedDataset<
Subject = Self::Subject,
Predicate = Self::Predicate,
Object = Self::Object,
GraphLabel = Self::GraphLabel,
>,
>(
&mut self,
other: D,
) where
D::Graph: SizedGraph;
}
pub trait DatasetTake<
T: ?Sized = <Self as Dataset>::Subject,
U: ?Sized = <Self as Dataset>::Predicate,
V: ?Sized = <Self as Dataset>::Object,
W: ?Sized = <Self as Dataset>::GraphLabel,
>: MutableDataset where
Self::Graph: GraphTake,
{
#[allow(clippy::type_complexity)]
fn take(
&mut self,
quad: Quad<&T, &U, &V, &W>,
) -> Option<Quad<Self::Subject, Self::Predicate, Self::Object, Self::GraphLabel>>;
#[allow(clippy::type_complexity)]
fn take_match(
&mut self,
quad: Quad<Option<&T>, Option<&U>, Option<&V>, Option<&W>>,
) -> Option<Quad<Self::Subject, Self::Predicate, Self::Object, Self::GraphLabel>>;
}