use std::error::Error;
use crate::graph::*;
use crate::triple::streaming_mode::*;
use crate::triple::*;
mod _error;
pub use self::_error::*;
mod _filter;
pub use self::_filter::*;
mod _filter_map;
pub use self::_filter_map::*;
mod _iterator;
pub use self::_iterator::*;
mod _map;
pub use self::_map::*;
pub type TsTerm<S> =
<<<S as TripleSource>::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term;
#[allow(clippy::upper_case_acronyms)]
#[deprecated(
since = "0.6.3",
note = "Was renamed to TsTerm, according to naming conventions"
)]
pub type TSTerm<S> = TsTerm<S>;
pub trait TripleSource {
type Error: 'static + Error;
type Triple: TripleStreamingMode;
fn try_for_some_triple<F, E>(&mut self, f: &mut F) -> StreamResult<bool, Self::Error, E>
where
F: FnMut(StreamedTriple<Self::Triple>) -> Result<(), E>,
E: Error;
#[inline]
fn try_for_each_triple<F, E>(&mut self, f: F) -> StreamResult<(), Self::Error, E>
where
F: FnMut(StreamedTriple<Self::Triple>) -> Result<(), E>,
E: Error,
{
let mut f = f;
while self.try_for_some_triple(&mut f)? {}
Ok(())
}
#[inline]
fn for_some_triple<F>(&mut self, f: &mut F) -> Result<bool, Self::Error>
where
F: FnMut(StreamedTriple<Self::Triple>),
{
self.try_for_some_triple(&mut |t| -> Result<(), Self::Error> {
f(t);
Ok(())
})
.map_err(StreamError::inner_into)
}
#[inline]
fn for_each_triple<F>(&mut self, f: F) -> Result<(), Self::Error>
where
F: FnMut(StreamedTriple<Self::Triple>),
{
let mut f = f;
while self.for_some_triple(&mut f)? {}
Ok(())
}
#[inline]
fn filter_triples<F>(self, filter: F) -> FilterSource<Self, F>
where
Self: Sized,
F: FnMut(&StreamedTriple<Self::Triple>) -> bool,
{
FilterSource {
source: self,
filter,
}
}
#[inline]
fn filter_map_triples<F, T>(self, filter_map: F) -> FilterMapSource<Self, F>
where
Self: Sized,
F: FnMut(StreamedTriple<Self::Triple>) -> Option<T>,
{
FilterMapSource {
source: self,
filter_map,
}
}
#[inline]
fn map_triples<F, T>(self, map: F) -> MapSource<Self, F>
where
Self: Sized,
F: FnMut(StreamedTriple<Self::Triple>) -> T,
{
MapSource { source: self, map }
}
fn size_hint_triples(&self) -> (usize, Option<usize>) {
(0, None)
}
fn collect_triples<G>(self) -> StreamResult<G, Self::Error, <G as Graph>::Error>
where
Self: Sized,
G: CollectibleGraph,
{
G::from_triple_source(self)
}
#[inline]
fn add_to_graph<G: MutableGraph>(
self,
graph: &mut G,
) -> StreamResult<usize, Self::Error, <G as MutableGraph>::MutationError>
where
Self: Sized,
{
graph.insert_all(self)
}
}
#[cfg(test)]
mod test;