pub trait Graph {
type Triple<'x>: Triple
where Self: 'x;
type Error: Error + Send + Sync + 'static;
Show 14 methods
// Required method
fn triples(
&self,
) -> impl Iterator<Item = GResult<Self, Self::Triple<'_>>> + '_;
// Provided methods
fn triples_matching<'s, S, P, O>(
&'s self,
sm: S,
pm: P,
om: O,
) -> impl Iterator<Item = GResult<Self, Self::Triple<'s>>> + 's
where S: TermMatcher + 's,
P: TermMatcher + 's,
O: TermMatcher + 's { ... }
fn contains<TS, TP, TO>(&self, s: TS, p: TP, o: TO) -> GResult<Self, bool>
where TS: Term,
TP: Term,
TO: Term { ... }
fn subjects(
&self,
) -> impl Iterator<Item = GResult<Self, GTerm<'_, Self>>> + '_ { ... }
fn predicates(
&self,
) -> impl Iterator<Item = GResult<Self, GTerm<'_, Self>>> + '_ { ... }
fn objects(
&self,
) -> impl Iterator<Item = GResult<Self, GTerm<'_, Self>>> + '_ { ... }
fn iris(&self) -> impl Iterator<Item = GResult<Self, GTerm<'_, Self>>> + '_ { ... }
fn blank_nodes(
&self,
) -> impl Iterator<Item = GResult<Self, GTerm<'_, Self>>> + '_ { ... }
fn literals(
&self,
) -> impl Iterator<Item = GResult<Self, GTerm<'_, Self>>> + '_ { ... }
fn quoted_triples<'s>(
&'s self,
) -> Box<dyn Iterator<Item = GResult<Self, GTerm<'_, Self>>> + '_>
where GTerm<'s, Self>: Clone { ... }
fn variables(
&self,
) -> impl Iterator<Item = GResult<Self, GTerm<'_, Self>>> + '_ { ... }
fn as_dataset(&self) -> GraphAsDataset<&Self> { ... }
fn as_dataset_mut(&mut self) -> GraphAsDataset<&mut Self> { ... }
fn into_dataset(self) -> GraphAsDataset<Self>
where Self: Sized { ... }
}Expand description
Generic trait for RDF graphs.
For convenience, this trait is implemented by standard collections of triples.
NB: the semantics of this trait allows a graph to contain duplicate triples;
see also SetGraph.
Required Associated Types§
Required Methods§
Sourcefn triples(&self) -> impl Iterator<Item = GResult<Self, Self::Triple<'_>>> + '_
fn triples(&self) -> impl Iterator<Item = GResult<Self, Self::Triple<'_>>> + '_
An iterator visiting all triples of this graph in arbitrary order.
This iterator is fallible:
its items are Results,
an error may occur at any time during the iteration.
§Examples
The result of this method is an iterator,
so it can be used in a for loop:
for t in graph.triples() {
let t = t?; // rethrow error if any
// do something with t
}Another way is to use the specific methods provided by TripleSource,
for example:
graph.triples().for_each_triple(|t| {
// do something with t
})?; // rethrow error if anyProvided Methods§
Sourcefn triples_matching<'s, S, P, O>(
&'s self,
sm: S,
pm: P,
om: O,
) -> impl Iterator<Item = GResult<Self, Self::Triple<'s>>> + 's
fn triples_matching<'s, S, P, O>( &'s self, sm: S, pm: P, om: O, ) -> impl Iterator<Item = GResult<Self, Self::Triple<'s>>> + 's
An iterator visiting all triples matching the given subject, predicate and object.
See crate::term::matcher.
See also triples.
§Usage
Typical implementations of TermMatcher include arrays/slices of Terms,
closure accepting a SimpleTerm, or the special matcher Any.
let s = Namespace::new("http://schema.org/")?;
let city = s.get("City")?;
let country = s.get("Country")?;
for t in graph.triples_matching(Any, [&rdf::type_], [city, country]) {
println!("{:?} was found", t?.s());
}Here is another example using a closure as a TermMatcher.
for t in graph.triples_matching(
Any,
[&rdfs::label],
|t: SimpleTerm| t.lexical_form().map(|v| v.contains("needle")).unwrap_or(false),
) {
println!("{:?} was found", t?.s());
}Sourcefn contains<TS, TP, TO>(&self, s: TS, p: TP, o: TO) -> GResult<Self, bool>
fn contains<TS, TP, TO>(&self, s: TS, p: TP, o: TO) -> GResult<Self, bool>
Return true if this graph contains the given triple.
Sourcefn subjects(&self) -> impl Iterator<Item = GResult<Self, GTerm<'_, Self>>> + '_
fn subjects(&self) -> impl Iterator<Item = GResult<Self, GTerm<'_, Self>>> + '_
Build a fallible iterator of all the terms used as subject in this Graph.
NB: implementations SHOULD avoid yielding the same term multiple times, but MAY do so. Users MUST therefore be prepared to deal with duplicates.
Sourcefn predicates(
&self,
) -> impl Iterator<Item = GResult<Self, GTerm<'_, Self>>> + '_
fn predicates( &self, ) -> impl Iterator<Item = GResult<Self, GTerm<'_, Self>>> + '_
Build a fallible iterator of all the terms used as predicate in this Graph.
NB: implementations SHOULD avoid yielding the same term multiple times, but MAY do so. Users MUST therefore be prepared to deal with duplicates.
Sourcefn objects(&self) -> impl Iterator<Item = GResult<Self, GTerm<'_, Self>>> + '_
fn objects(&self) -> impl Iterator<Item = GResult<Self, GTerm<'_, Self>>> + '_
Build a fallible iterator of all the terms used as object in this Graph.
NB: implementations SHOULD avoid yielding the same term multiple times, but MAY do so. Users MUST therefore be prepared to deal with duplicates.
Sourcefn iris(&self) -> impl Iterator<Item = GResult<Self, GTerm<'_, Self>>> + '_
fn iris(&self) -> impl Iterator<Item = GResult<Self, GTerm<'_, Self>>> + '_
Build a fallible iterator of all the IRIs used in this Graph (including those used inside quoted triples, if any).
NB: implementations SHOULD avoid yielding the same term multiple times, but MAY do so. Users MUST therefore be prepared to deal with duplicates.
Sourcefn blank_nodes(
&self,
) -> impl Iterator<Item = GResult<Self, GTerm<'_, Self>>> + '_
fn blank_nodes( &self, ) -> impl Iterator<Item = GResult<Self, GTerm<'_, Self>>> + '_
Build a fallible iterator of all the blank nodes used in this Graph (including those used inside quoted triples, if any).
NB: implementations SHOULD avoid yielding the same term multiple times, but MAY do so. Users MUST therefore be prepared to deal with duplicates.
Sourcefn literals(&self) -> impl Iterator<Item = GResult<Self, GTerm<'_, Self>>> + '_
fn literals(&self) -> impl Iterator<Item = GResult<Self, GTerm<'_, Self>>> + '_
Build a fallible iterator of all the literals used in this Graph (including those used inside quoted triples, if any).
NB: implementations SHOULD avoid yielding the same term multiple times, but MAY do so. Users MUST therefore be prepared to deal with duplicates.
Sourcefn quoted_triples<'s>(
&'s self,
) -> Box<dyn Iterator<Item = GResult<Self, GTerm<'_, Self>>> + '_>
fn quoted_triples<'s>( &'s self, ) -> Box<dyn Iterator<Item = GResult<Self, GTerm<'_, Self>>> + '_>
Build a fallible iterator of all the quoted triples used in this Graph (including those used inside quoted triples, if any).
NB: implementations SHOULD avoid yielding the same term multiple times, but MAY do so. Users MUST therefore be prepared to deal with duplicates.
Sourcefn variables(&self) -> impl Iterator<Item = GResult<Self, GTerm<'_, Self>>> + '_
fn variables(&self) -> impl Iterator<Item = GResult<Self, GTerm<'_, Self>>> + '_
Build a fallible iterator of all the variables used in this Graph (including those used inside quoted triples, if any).
NB: implementations SHOULD avoid yielding the same term multiple times, but MAY do so. Users MUST therefore be prepared to deal with duplicates.
Sourcefn as_dataset(&self) -> GraphAsDataset<&Self>
fn as_dataset(&self) -> GraphAsDataset<&Self>
Dataset adapter borrowing this graph
Sourcefn as_dataset_mut(&mut self) -> GraphAsDataset<&mut Self>
fn as_dataset_mut(&mut self) -> GraphAsDataset<&mut Self>
Dataset adapter borrowing this graph mutably
Sourcefn into_dataset(self) -> GraphAsDataset<Self>where
Self: Sized,
fn into_dataset(self) -> GraphAsDataset<Self>where
Self: Sized,
Dataset adapter taking ownership of this graph
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl<'a, T: Graph + ?Sized> Graph for &'a T
impl<'a, T: Graph + ?Sized> Graph for &'a T
type Triple<'x> = <T as Graph>::Triple<'x> where Self: 'x
type Error = <T as Graph>::Error
fn triples(&self) -> impl Iterator<Item = GResult<Self, Self::Triple<'_>>> + '_
fn triples_matching<'s, S, P, O>( &'s self, sm: S, pm: P, om: O, ) -> impl Iterator<Item = GResult<Self, Self::Triple<'s>>> + 's
fn contains<TS, TP, TO>(&self, s: TS, p: TP, o: TO) -> GResult<Self, bool>
fn subjects(&self) -> impl Iterator<Item = GResult<Self, GTerm<'_, Self>>> + '_
fn predicates( &self, ) -> impl Iterator<Item = GResult<Self, GTerm<'_, Self>>> + '_
fn objects(&self) -> impl Iterator<Item = GResult<Self, GTerm<'_, Self>>> + '_
fn iris(&self) -> impl Iterator<Item = GResult<Self, GTerm<'_, Self>>> + '_
fn blank_nodes( &self, ) -> impl Iterator<Item = GResult<Self, GTerm<'_, Self>>> + '_
fn literals(&self) -> impl Iterator<Item = GResult<Self, GTerm<'_, Self>>> + '_
fn quoted_triples<'s>( &'s self, ) -> Box<dyn Iterator<Item = GResult<Self, GTerm<'_, Self>>> + '_>
fn variables(&self) -> impl Iterator<Item = GResult<Self, GTerm<'_, Self>>> + '_
Source§impl<'a, T: Graph + ?Sized> Graph for &'a mut T
impl<'a, T: Graph + ?Sized> Graph for &'a mut T
type Triple<'x> = <T as Graph>::Triple<'x> where Self: 'x
type Error = <T as Graph>::Error
fn triples(&self) -> impl Iterator<Item = GResult<Self, Self::Triple<'_>>> + '_
fn triples_matching<'s, S, P, O>( &'s self, sm: S, pm: P, om: O, ) -> impl Iterator<Item = GResult<Self, Self::Triple<'s>>> + 's
fn contains<TS, TP, TO>(&self, s: TS, p: TP, o: TO) -> GResult<Self, bool>
fn subjects(&self) -> impl Iterator<Item = GResult<Self, GTerm<'_, Self>>> + '_
fn predicates( &self, ) -> impl Iterator<Item = GResult<Self, GTerm<'_, Self>>> + '_
fn objects(&self) -> impl Iterator<Item = GResult<Self, GTerm<'_, Self>>> + '_
fn iris(&self) -> impl Iterator<Item = GResult<Self, GTerm<'_, Self>>> + '_
fn blank_nodes( &self, ) -> impl Iterator<Item = GResult<Self, GTerm<'_, Self>>> + '_
fn literals(&self) -> impl Iterator<Item = GResult<Self, GTerm<'_, Self>>> + '_
fn quoted_triples<'s>( &'s self, ) -> Box<dyn Iterator<Item = GResult<Self, GTerm<'_, Self>>> + '_>
fn variables(&self) -> impl Iterator<Item = GResult<Self, GTerm<'_, Self>>> + '_
Source§impl<T: Triple> Graph for BTreeSet<T>
NB: This is a straightforward and minimal implementation,
not taking advantage of the order of terms to optimize Graph::triples_matching
nor other methods.
impl<T: Triple> Graph for BTreeSet<T>
NB: This is a straightforward and minimal implementation,
not taking advantage of the order of terms to optimize Graph::triples_matching
nor other methods.