@ -155,17 +155,24 @@ impl RocksDbStore {
predicate : Option < NamedNodeRef < ' _ > > ,
object : Option < TermRef < ' _ > > ,
graph_name : Option < GraphNameRef < ' _ > > ,
) -> impl Iterator < Item = Result < Quad , io ::Error > > {
match get_encoded_quad_pattern ( self , subject , predicate , object , graph_name ) {
Ok ( Some ( ( subject , predicate , object , graph_name ) ) ) = > QuadsIter ::Quads {
iter : self . encoded_quads_for_pattern ( subject , predicate , object , graph_name ) ,
store : self . clone ( ) ,
) -> RocksDbQuadIter {
RocksDbQuadIter {
inner : match get_encoded_quad_pattern ( self , subject , predicate , object , graph_name ) {
Ok ( Some ( ( subject , predicate , object , graph_name ) ) ) = > QuadIterInner ::Quads {
iter : self . encoded_quads_for_pattern ( subject , predicate , object , graph_name ) ,
store : self . clone ( ) ,
} ,
Ok ( None ) = > QuadIterInner ::Empty ,
Err ( error ) = > QuadIterInner ::Error ( once ( error ) ) ,
} ,
Ok ( None ) = > QuadsIter ::Empty ,
Err ( error ) = > QuadsIter ::Error ( once ( error ) ) ,
}
}
/// Returns all the quads contained in the store
pub fn iter ( & self ) -> RocksDbQuadIter {
self . quads_for_pattern ( None , None , None , None )
}
/// Checks if this store contains a given quad
pub fn contains < ' a > ( & self , quad : impl Into < QuadRef < ' a > > ) -> Result < bool , io ::Error > {
if let Some ( quad ) = self . get_encoded_quad ( quad . into ( ) ) ? {
@ -318,11 +325,7 @@ impl RocksDbStore {
///
/// See [`MemoryStore`](../memory/struct.MemoryStore.html#method.dump_dataset) for a usage example.
pub fn dump_dataset ( & self , writer : impl Write , syntax : DatasetFormat ) -> Result < ( ) , io ::Error > {
dump_dataset (
self . quads_for_pattern ( None , None , None , None ) ,
writer ,
syntax ,
)
dump_dataset ( self . iter ( ) , writer , syntax )
}
fn id2str_cf ( & self ) -> & ColumnFamily {
@ -617,7 +620,7 @@ impl RocksDbStore {
impl fmt ::Display for RocksDbStore {
fn fmt ( & self , f : & mut fmt ::Formatter < ' _ > ) -> fmt ::Result {
for t in self . quads_for_pattern ( None , None , None , None ) {
for t in self . iter ( ) {
writeln! ( f , "{}" , t . map_err ( | _ | fmt ::Error ) ? ) ? ;
}
Ok ( ( ) )
@ -1161,7 +1164,12 @@ fn map_err(e: Error) -> io::Error {
io ::Error ::new ( io ::ErrorKind ::Other , e )
}
enum QuadsIter {
/// An iterator returning the quads contained in a [`RocksDbStore`](struct.RocksDbStore.html).
pub struct RocksDbQuadIter {
inner : QuadIterInner ,
}
enum QuadIterInner {
Quads {
iter : DecodingIndexesIterator ,
store : RocksDbStore ,
@ -1170,17 +1178,17 @@ enum QuadsIter {
Empty ,
}
impl Iterator for Quads Iter {
impl Iterator for RocksDb QuadIter {
type Item = Result < Quad , io ::Error > ;
fn next ( & mut self ) -> Option < Result < Quad , io ::Error > > {
match self {
Self ::Quads { iter , store } = > Some ( match iter . next ( ) ? {
match & mut self . inner {
QuadIterInner ::Quads { iter , store } = > Some ( match iter . next ( ) ? {
Ok ( quad ) = > store . decode_quad ( & quad ) . map_err ( | e | e . into ( ) ) ,
Err ( error ) = > Err ( error ) ,
} ) ,
Self ::Error ( iter ) = > iter . next ( ) . map ( Err ) ,
Self ::Empty = > None ,
QuadIterInner ::Error ( iter ) = > iter . next ( ) . map ( Err ) ,
QuadIterInner ::Empty = > None ,
}
}
}
@ -1242,12 +1250,7 @@ fn store() -> Result<(), io::Error> {
} ) ? ;
assert_eq! ( store . len ( ) , 4 ) ;
assert_eq! (
store
. quads_for_pattern ( None , None , None , None )
. collect ::< Result < Vec < _ > , _ > > ( ) ? ,
all_quads
) ;
assert_eq! ( store . iter ( ) . collect ::< Result < Vec < _ > , _ > > ( ) ? , all_quads ) ;
assert_eq! (
store
. quads_for_pattern ( Some ( main_s . as_ref ( ) ) , None , None , None )