[−][src]Module sophia::triple::stream
A triple source produces triples, and may also fail in the process.
The trait TripleSource
provides an API similar to (a subset of) the Iterator
API,
with methods such as for_each_triple
and try_for_each_triple
.
Rationale (or Why not simply use Iterator
?)
The Iterator
trait is designed in such a way that items must live at least as long as the iterator itself.
This assumption may be too strong in some situations.
For example,
consider a parser using 3 buffers to store the subject, predicate,
and object of the triples it parses.
Each time it extracts a triple from the data,
it yields it (as 3 references to its internal buffers)
to the closure passed to for_each_triple
.
Then, it reuses the buffers to store the data for the next triple,
and yields the new triple, as 3 references to the same buffers.
Such a parser can not implement Iterator
,
because, once yielded by the iterator's next
method,
an item is free to live during further iterations.
In particular, it can be stored in a vector,
and still be alive when the next
method is called again
(consider for example the Iterator::collect
method).
Because many parsers (as well as other triple sources) will be implemented in a manner similar to that described above, we have to provide a trait with weaker assumptions on the lifetime of the yielded triples.
The alternative would be to wrap such parsers with a layer that would copy the data from internal buffers to fresh buffers for each triples, but we do not want to impose that cost on all implementations — especially when many consumers will be happy with short-lived references.
Structs
FilterMapSource | The result of
|
FilterMapSourceIterator | An iterator over the result of
|
FilterSource | The result of
|
MapSource | The result of
|
MapSourceIterator | An iterator over the result of
|
Enums
StreamError | A error that is raised by functions that move fallible |
Traits
AsTripleSource | A utility extension trait for converting any iterator of |
SinkResult | Extension trait for |
SourceResult | Extension trait for |
TripleSource | A triple source produces triples, and may also fail in the process. |
Type Definitions
AsInfallibleSource | |
StreamResult | Convenient type alias |
TSTerm | Type alias for referencing the |