From c18281183a553ae2e64189d0c34c75f4889e1d1f Mon Sep 17 00:00:00 2001 From: Tpt Date: Mon, 31 May 2021 19:33:26 +0200 Subject: [PATCH] Uses std::io::Result where relevant --- lib/src/io/read.rs | 16 ++++----- lib/src/io/write.rs | 12 +++---- lib/src/model/dataset.rs | 10 +++--- lib/src/model/graph.rs | 4 +-- lib/src/sparql/csv_results.rs | 4 +-- lib/src/sparql/json_results.rs | 8 ++--- lib/src/sparql/model.rs | 5 +-- lib/src/sparql/xml_results.rs | 2 +- lib/src/storage/binary_encoder.rs | 26 +++++++-------- lib/src/storage/io.rs | 8 ++--- lib/src/storage/mod.rs | 54 +++++++++++++++---------------- lib/src/store.rs | 45 ++++++++++++-------------- 12 files changed, 93 insertions(+), 101 deletions(-) diff --git a/lib/src/io/read.rs b/lib/src/io/read.rs index d4056a10..2f542cf0 100644 --- a/lib/src/io/read.rs +++ b/lib/src/io/read.rs @@ -66,7 +66,7 @@ impl GraphParser { } /// Executes the parsing itself on a [`BufRead`](std::io::BufRead) implementation and returns an iterator of triples - pub fn read_triples(&self, reader: R) -> Result, io::Error> { + pub fn read_triples(&self, reader: R) -> io::Result> { Ok(TripleReader { mapper: RioMapper::default(), parser: match self.format { @@ -113,9 +113,9 @@ enum TripleReaderKind { } impl Iterator for TripleReader { - type Item = Result; + type Item = io::Result; - fn next(&mut self) -> Option> { + fn next(&mut self) -> Option> { loop { if let Some(r) = self.buffer.pop() { return Some(Ok(r)); @@ -143,7 +143,7 @@ impl TripleReader { parser: &mut P, buffer: &mut Vec, mapper: &mut RioMapper, - ) -> Option> + ) -> Option> where io::Error: From, { @@ -214,7 +214,7 @@ impl DatasetParser { } /// Executes the parsing itself on a [`BufRead`](std::io::BufRead) implementation and returns an iterator of quads - pub fn read_quads(&self, reader: R) -> Result, io::Error> { + pub fn read_quads(&self, reader: R) -> io::Result> { Ok(QuadReader { mapper: RioMapper::default(), parser: match self.format { @@ -257,9 +257,9 @@ enum QuadReaderKind { } impl Iterator for QuadReader { - type Item = Result; + type Item = io::Result; - fn next(&mut self) -> Option> { + fn next(&mut self) -> Option> { loop { if let Some(r) = self.buffer.pop() { return Some(Ok(r)); @@ -284,7 +284,7 @@ impl QuadReader { parser: &mut P, buffer: &mut Vec, mapper: &mut RioMapper, - ) -> Option> + ) -> Option> where io::Error: From, { diff --git a/lib/src/io/write.rs b/lib/src/io/write.rs index b8e57a28..e8f72515 100644 --- a/lib/src/io/write.rs +++ b/lib/src/io/write.rs @@ -43,7 +43,7 @@ impl GraphSerializer { } /// Returns a `TripleWriter` allowing writing triples into the given [`Write`](std::io::Write) implementation - pub fn triple_writer(&self, writer: W) -> Result, io::Error> { + pub fn triple_writer(&self, writer: W) -> io::Result> { Ok(TripleWriter { formatter: match self.format { GraphFormat::NTriples => TripleWriterKind::NTriples(NTriplesFormatter::new(writer)), @@ -88,7 +88,7 @@ enum TripleWriterKind { impl TripleWriter { /// Writes a triple - pub fn write<'a>(&mut self, triple: impl Into>) -> Result<(), io::Error> { + pub fn write<'a>(&mut self, triple: impl Into>) -> io::Result<()> { let triple = triple.into(); match &mut self.formatter { TripleWriterKind::NTriples(formatter) => formatter.format(&triple.into())?, @@ -99,7 +99,7 @@ impl TripleWriter { } /// Writes the last bytes of the file - pub fn finish(self) -> Result<(), io::Error> { + pub fn finish(self) -> io::Result<()> { match self.formatter { TripleWriterKind::NTriples(formatter) => formatter.finish(), TripleWriterKind::Turtle(formatter) => formatter.finish()?, @@ -144,7 +144,7 @@ impl DatasetSerializer { } /// Returns a `QuadWriter` allowing writing triples into the given [`Write`](std::io::Write) implementation - pub fn quad_writer(&self, writer: W) -> Result, io::Error> { + pub fn quad_writer(&self, writer: W) -> io::Result> { Ok(QuadWriter { formatter: match self.format { DatasetFormat::NQuads => QuadWriterKind::NQuads(NQuadsFormatter::new(writer)), @@ -188,7 +188,7 @@ enum QuadWriterKind { impl QuadWriter { /// Writes a quad - pub fn write<'a>(&mut self, quad: impl Into>) -> Result<(), io::Error> { + pub fn write<'a>(&mut self, quad: impl Into>) -> io::Result<()> { let quad = quad.into(); match &mut self.formatter { QuadWriterKind::NQuads(formatter) => formatter.format(&quad.into())?, @@ -198,7 +198,7 @@ impl QuadWriter { } /// Writes the last bytes of the file - pub fn finish(self) -> Result<(), io::Error> { + pub fn finish(self) -> io::Result<()> { match self.formatter { QuadWriterKind::NQuads(formatter) => formatter.finish(), QuadWriterKind::TriG(formatter) => formatter.finish()?, diff --git a/lib/src/model/dataset.rs b/lib/src/model/dataset.rs index 2edc00d8..cd0536b7 100644 --- a/lib/src/model/dataset.rs +++ b/lib/src/model/dataset.rs @@ -436,7 +436,7 @@ impl Dataset { reader: impl BufRead, format: DatasetFormat, base_iri: Option<&str>, - ) -> Result<(), io::Error> { + ) -> io::Result<()> { let mut parser = DatasetParser::from_format(format); if let Some(base_iri) = base_iri { parser = parser @@ -468,7 +468,7 @@ impl Dataset { /// assert_eq!(file, buffer.as_slice()); /// # Result::<_,Box>::Ok(()) /// ``` - pub fn dump(&self, writer: impl Write, format: DatasetFormat) -> Result<(), io::Error> { + pub fn dump(&self, writer: impl Write, format: DatasetFormat) -> io::Result<()> { let mut writer = DatasetSerializer::from_format(format).quad_writer(writer)?; for t in self { writer.write(t)?; @@ -1265,7 +1265,7 @@ impl<'a> GraphView<'a> { /// assert_eq!(file, buffer.as_slice()); /// # Result::<_,Box>::Ok(()) /// ``` - pub fn dump(&self, writer: impl Write, format: GraphFormat) -> Result<(), io::Error> { + pub fn dump(&self, writer: impl Write, format: GraphFormat) -> io::Result<()> { let mut writer = GraphSerializer::from_format(format).triple_writer(writer)?; for t in self { writer.write(t)?; @@ -1402,7 +1402,7 @@ impl<'a> GraphViewMut<'a> { reader: impl BufRead, format: GraphFormat, base_iri: Option<&str>, - ) -> Result<(), io::Error> { + ) -> io::Result<()> { let mut parser = GraphParser::from_format(format); if let Some(base_iri) = base_iri { parser = parser @@ -1538,7 +1538,7 @@ impl<'a> GraphViewMut<'a> { /// assert_eq!(file, buffer.as_slice()); /// # Result::<_,Box>::Ok(()) /// ``` - pub fn dump(self, writer: impl Write, format: GraphFormat) -> Result<(), io::Error> { + pub fn dump(self, writer: impl Write, format: GraphFormat) -> io::Result<()> { self.read().dump(writer, format) } } diff --git a/lib/src/model/graph.rs b/lib/src/model/graph.rs index c7c2241b..471374f0 100644 --- a/lib/src/model/graph.rs +++ b/lib/src/model/graph.rs @@ -208,7 +208,7 @@ impl Graph { reader: impl BufRead, format: GraphFormat, base_iri: Option<&str>, - ) -> Result<(), io::Error> { + ) -> io::Result<()> { self.graph_mut().load(reader, format, base_iri) } @@ -229,7 +229,7 @@ impl Graph { /// assert_eq!(file, buffer.as_slice()); /// # Result::<_,Box>::Ok(()) /// ``` - pub fn dump(&self, writer: impl Write, format: GraphFormat) -> Result<(), io::Error> { + pub fn dump(&self, writer: impl Write, format: GraphFormat) -> io::Result<()> { self.graph().dump(writer, format) } diff --git a/lib/src/sparql/csv_results.rs b/lib/src/sparql/csv_results.rs index 21ac1662..d2d3a87f 100644 --- a/lib/src/sparql/csv_results.rs +++ b/lib/src/sparql/csv_results.rs @@ -178,7 +178,7 @@ fn write_tsv_term<'a>(term: impl Into>, sink: &mut impl Write) -> io } } -pub fn read_tsv_results(mut source: impl BufRead + 'static) -> Result { +pub fn read_tsv_results(mut source: impl BufRead + 'static) -> io::Result { let mut buffer = String::new(); // We read the header @@ -192,7 +192,7 @@ pub fn read_tsv_results(mut source: impl BufRead + 'static) -> Result, io::Error>>()?; + .collect::>>()?; Ok(QueryResults::Solutions(QuerySolutionIter::new( Rc::new(variables), diff --git a/lib/src/sparql/json_results.rs b/lib/src/sparql/json_results.rs index 6b3321f1..96d54422 100644 --- a/lib/src/sparql/json_results.rs +++ b/lib/src/sparql/json_results.rs @@ -115,7 +115,7 @@ fn write_json_term( Ok(()) } -pub fn read_json_results(source: impl BufRead + 'static) -> Result { +pub fn read_json_results(source: impl BufRead + 'static) -> io::Result { let mut reader = JsonReader::from_reader(source); let mut buffer = Vec::default(); let mut variables = None; @@ -423,8 +423,7 @@ impl ResultsIterator { Term::Literal(_) => { return Err(invalid_data_error( "The 'subject' value should not be a literal", - ) - .into()) + )) } }, match predicate.ok_or_else(|| { @@ -436,8 +435,7 @@ impl ResultsIterator { _ => { return Err(invalid_data_error( "The 'predicate' value should be a uri", - ) - .into()) + )) } }, object.ok_or_else(|| { diff --git a/lib/src/sparql/model.rs b/lib/src/sparql/model.rs index 078ae7ba..2393bdad 100644 --- a/lib/src/sparql/model.rs +++ b/lib/src/sparql/model.rs @@ -23,10 +23,7 @@ pub enum QueryResults { impl QueryResults { /// Reads a SPARQL query results serialization - pub fn read( - reader: impl BufRead + 'static, - format: QueryResultsFormat, - ) -> Result { + pub fn read(reader: impl BufRead + 'static, format: QueryResultsFormat) -> io::Result { match format { QueryResultsFormat::Xml => read_xml_results(reader), QueryResultsFormat::Json => read_json_results(reader), diff --git a/lib/src/sparql/xml_results.rs b/lib/src/sparql/xml_results.rs index d056e8fe..5f773ba1 100644 --- a/lib/src/sparql/xml_results.rs +++ b/lib/src/sparql/xml_results.rs @@ -183,7 +183,7 @@ fn write_xml_term( Ok(()) } -pub fn read_xml_results(source: impl BufRead + 'static) -> Result { +pub fn read_xml_results(source: impl BufRead + 'static) -> io::Result { enum State { Start, Sparql, diff --git a/lib/src/storage/binary_encoder.rs b/lib/src/storage/binary_encoder.rs index 7429f5d4..db1a111e 100644 --- a/lib/src/storage/binary_encoder.rs +++ b/lib/src/storage/binary_encoder.rs @@ -63,7 +63,7 @@ pub enum QuadEncoding { } impl QuadEncoding { - pub fn decode(self, buffer: &[u8]) -> Result { + pub fn decode(self, buffer: &[u8]) -> io::Result { let mut cursor = Cursor::new(&buffer); match self { QuadEncoding::Spog => cursor.read_spog_quad(), @@ -79,14 +79,14 @@ impl QuadEncoding { } } -pub fn decode_term(buffer: &[u8]) -> Result { +pub fn decode_term(buffer: &[u8]) -> io::Result { Cursor::new(&buffer).read_term() } pub trait TermReader { - fn read_term(&mut self) -> Result; + fn read_term(&mut self) -> io::Result; - fn read_spog_quad(&mut self) -> Result { + fn read_spog_quad(&mut self) -> io::Result { let subject = self.read_term()?; let predicate = self.read_term()?; let object = self.read_term()?; @@ -99,7 +99,7 @@ pub trait TermReader { }) } - fn read_posg_quad(&mut self) -> Result { + fn read_posg_quad(&mut self) -> io::Result { let predicate = self.read_term()?; let object = self.read_term()?; let subject = self.read_term()?; @@ -112,7 +112,7 @@ pub trait TermReader { }) } - fn read_ospg_quad(&mut self) -> Result { + fn read_ospg_quad(&mut self) -> io::Result { let object = self.read_term()?; let subject = self.read_term()?; let predicate = self.read_term()?; @@ -125,7 +125,7 @@ pub trait TermReader { }) } - fn read_gspo_quad(&mut self) -> Result { + fn read_gspo_quad(&mut self) -> io::Result { let graph_name = self.read_term()?; let subject = self.read_term()?; let predicate = self.read_term()?; @@ -138,7 +138,7 @@ pub trait TermReader { }) } - fn read_gpos_quad(&mut self) -> Result { + fn read_gpos_quad(&mut self) -> io::Result { let graph_name = self.read_term()?; let predicate = self.read_term()?; let object = self.read_term()?; @@ -151,7 +151,7 @@ pub trait TermReader { }) } - fn read_gosp_quad(&mut self) -> Result { + fn read_gosp_quad(&mut self) -> io::Result { let graph_name = self.read_term()?; let object = self.read_term()?; let subject = self.read_term()?; @@ -164,7 +164,7 @@ pub trait TermReader { }) } - fn read_dspo_quad(&mut self) -> Result { + fn read_dspo_quad(&mut self) -> io::Result { let subject = self.read_term()?; let predicate = self.read_term()?; let object = self.read_term()?; @@ -176,7 +176,7 @@ pub trait TermReader { }) } - fn read_dpos_quad(&mut self) -> Result { + fn read_dpos_quad(&mut self) -> io::Result { let predicate = self.read_term()?; let object = self.read_term()?; let subject = self.read_term()?; @@ -188,7 +188,7 @@ pub trait TermReader { }) } - fn read_dosp_quad(&mut self) -> Result { + fn read_dosp_quad(&mut self) -> io::Result { let object = self.read_term()?; let subject = self.read_term()?; let predicate = self.read_term()?; @@ -202,7 +202,7 @@ pub trait TermReader { } impl TermReader for R { - fn read_term(&mut self) -> Result { + fn read_term(&mut self) -> io::Result { let mut type_buffer = [0]; self.read_exact(&mut type_buffer)?; match type_buffer[0] { diff --git a/lib/src/storage/io.rs b/lib/src/storage/io.rs index 348c19b6..8e331945 100644 --- a/lib/src/storage/io.rs +++ b/lib/src/storage/io.rs @@ -60,10 +60,10 @@ where } pub fn dump_graph( - triples: impl Iterator>, + triples: impl Iterator>, writer: impl Write, format: GraphFormat, -) -> Result<(), io::Error> { +) -> io::Result<()> { let mut writer = GraphSerializer::from_format(format).triple_writer(writer)?; for triple in triples { writer.write(&triple?)?; @@ -106,10 +106,10 @@ where } pub fn dump_dataset( - quads: impl Iterator>, + quads: impl Iterator>, writer: impl Write, format: DatasetFormat, -) -> Result<(), io::Error> { +) -> io::Result<()> { let mut writer = DatasetSerializer::from_format(format).quad_writer(writer)?; for quad in quads { writer.write(&quad?)?; diff --git a/lib/src/storage/mod.rs b/lib/src/storage/mod.rs index a223a300..a4f45cce 100644 --- a/lib/src/storage/mod.rs +++ b/lib/src/storage/mod.rs @@ -43,15 +43,15 @@ pub struct Storage { } impl Storage { - pub fn new() -> Result { + pub fn new() -> std::io::Result { Self::do_open(&Config::new().temporary(true)) } - pub fn open(path: &Path) -> Result { + pub fn open(path: &Path) -> std::io::Result { Self::do_open(&Config::new().path(path)) } - fn do_open(config: &Config) -> Result { + fn do_open(config: &Config) -> std::io::Result { let db = config.open()?; let this = Self { default: db.clone(), @@ -95,7 +95,7 @@ impl Storage { } } - fn ensure_version(&self) -> Result { + fn ensure_version(&self) -> std::io::Result { Ok(if let Some(version) = self.default.get("oxversion")? { let mut buffer = [0; 8]; buffer.copy_from_slice(&version); @@ -106,7 +106,7 @@ impl Storage { }) } - fn set_version(&self, version: u64) -> Result<(), std::io::Error> { + fn set_version(&self, version: u64) -> std::io::Result<()> { self.default.insert("oxversion", &version.to_be_bytes())?; Ok(()) } @@ -155,7 +155,7 @@ impl Storage { self.gspo.is_empty() && self.dspo.is_empty() } - pub fn contains(&self, quad: &EncodedQuad) -> Result { + pub fn contains(&self, quad: &EncodedQuad) -> std::io::Result { let mut buffer = Vec::with_capacity(4 * WRITTEN_TERM_MAX_SIZE); if quad.graph_name.is_default_graph() { write_spo_quad(&mut buffer, quad); @@ -405,7 +405,7 @@ impl Storage { } } - pub fn contains_named_graph(&self, graph_name: &EncodedTerm) -> Result { + pub fn contains_named_graph(&self, graph_name: &EncodedTerm) -> std::io::Result { Ok(self.graphs.contains_key(&encode_term(graph_name))?) } @@ -457,7 +457,7 @@ impl Storage { } } - pub fn insert(&self, quad: &EncodedQuad) -> Result { + pub fn insert(&self, quad: &EncodedQuad) -> std::io::Result { let mut buffer = Vec::with_capacity(4 * WRITTEN_TERM_MAX_SIZE + 1); if quad.graph_name.is_default_graph() { @@ -512,7 +512,7 @@ impl Storage { } } - pub fn remove(&self, quad: &EncodedQuad) -> Result { + pub fn remove(&self, quad: &EncodedQuad) -> std::io::Result { let mut buffer = Vec::with_capacity(4 * WRITTEN_TERM_MAX_SIZE + 1); if quad.graph_name.is_default_graph() { @@ -564,11 +564,11 @@ impl Storage { } } - pub fn insert_named_graph(&self, graph_name: &EncodedTerm) -> Result { + pub fn insert_named_graph(&self, graph_name: &EncodedTerm) -> std::io::Result { Ok(self.graphs.insert(&encode_term(graph_name), &[])?.is_none()) } - pub fn clear_graph(&self, graph_name: &EncodedTerm) -> Result<(), std::io::Error> { + pub fn clear_graph(&self, graph_name: &EncodedTerm) -> std::io::Result<()> { if graph_name.is_default_graph() { self.dspo.clear()?; self.dpos.clear()?; @@ -581,14 +581,14 @@ impl Storage { Ok(()) } - pub fn remove_named_graph(&self, graph_name: &EncodedTerm) -> Result { + pub fn remove_named_graph(&self, graph_name: &EncodedTerm) -> std::io::Result { for quad in self.quads_for_graph(graph_name) { self.remove(&quad?)?; } Ok(self.graphs.remove(&encode_term(graph_name))?.is_some()) } - pub fn clear(&self) -> Result<(), std::io::Error> { + pub fn clear(&self) -> std::io::Result<()> { self.dspo.clear()?; self.dpos.clear()?; self.dosp.clear()?; @@ -603,17 +603,17 @@ impl Storage { Ok(()) } - pub fn flush(&self) -> Result<(), std::io::Error> { + pub fn flush(&self) -> std::io::Result<()> { self.default.flush()?; Ok(()) } - pub async fn flush_async(&self) -> Result<(), std::io::Error> { + pub async fn flush_async(&self) -> std::io::Result<()> { self.default.flush_async().await?; Ok(()) } - pub fn get_str(&self, key: &StrHash) -> Result, std::io::Error> { + pub fn get_str(&self, key: &StrHash) -> std::io::Result> { self.id2str .get(key.to_be_bytes())? .map(|v| String::from_utf8(v.to_vec())) @@ -621,11 +621,11 @@ impl Storage { .map_err(invalid_data_error) } - pub fn contains_str(&self, key: &StrHash) -> Result { + pub fn contains_str(&self, key: &StrHash) -> std::io::Result { Ok(self.id2str.contains_key(key.to_be_bytes())?) } - pub fn insert_str(&self, key: &StrHash, value: &str) -> Result { + pub fn insert_str(&self, key: &StrHash, value: &str) -> std::io::Result { Ok(self.id2str.insert(key.to_be_bytes(), value)?.is_none()) } } @@ -652,9 +652,9 @@ impl ChainedDecodingQuadIterator { } impl Iterator for ChainedDecodingQuadIterator { - type Item = Result; + type Item = std::io::Result; - fn next(&mut self) -> Option> { + fn next(&mut self) -> Option> { if let Some(result) = self.first.next() { Some(result) } else if let Some(second) = self.second.as_mut() { @@ -671,9 +671,9 @@ pub struct DecodingQuadIterator { } impl Iterator for DecodingQuadIterator { - type Item = Result; + type Item = std::io::Result; - fn next(&mut self) -> Option> { + fn next(&mut self) -> Option> { Some(match self.iter.next()? { Ok((encoded, _)) => self.encoding.decode(&encoded), Err(error) => Err(error.into()), @@ -686,9 +686,9 @@ pub struct DecodingGraphIterator { } impl Iterator for DecodingGraphIterator { - type Item = Result; + type Item = std::io::Result; - fn next(&mut self) -> Option> { + fn next(&mut self) -> Option> { Some(match self.iter.next()? { Ok((encoded, _)) => decode_term(&encoded), Err(error) => Err(error.into()), @@ -1002,17 +1002,17 @@ impl From> for Sled2ConflictableTransactionEr impl StrLookup for Storage { type Error = std::io::Error; - fn get_str(&self, key: &StrHash) -> Result, std::io::Error> { + fn get_str(&self, key: &StrHash) -> std::io::Result> { self.get_str(key) } - fn contains_str(&self, key: &StrHash) -> Result { + fn contains_str(&self, key: &StrHash) -> std::io::Result { self.contains_str(key) } } impl StrContainer for Storage { - fn insert_str(&self, key: &StrHash, value: &str) -> Result { + fn insert_str(&self, key: &StrHash, value: &str) -> std::io::Result { self.insert_str(key, value) } } diff --git a/lib/src/store.rs b/lib/src/store.rs index 46e0da73..daee5319 100644 --- a/lib/src/store.rs +++ b/lib/src/store.rs @@ -86,14 +86,14 @@ pub struct Store { impl Store { /// Creates a temporary [`Store`]() that will be deleted after drop. - pub fn new() -> Result { + pub fn new() -> io::Result { Ok(Self { storage: Storage::new()?, }) } /// Opens a [`Store`]() and creates it if it does not exist yet. - pub fn open(path: impl AsRef) -> Result { + pub fn open(path: impl AsRef) -> io::Result { Ok(Self { storage: Storage::open(path.as_ref())?, }) @@ -178,7 +178,7 @@ impl Store { } /// Checks if this store contains a given quad - pub fn contains<'a>(&self, quad: impl Into>) -> Result { + pub fn contains<'a>(&self, quad: impl Into>) -> io::Result { let quad = EncodedQuad::from(quad.into()); self.storage.contains(&quad) } @@ -303,7 +303,7 @@ impl Store { format: GraphFormat, to_graph_name: impl Into>, base_iri: Option<&str>, - ) -> Result<(), io::Error> { + ) -> io::Result<()> { load_graph( &self.storage, reader, @@ -347,7 +347,7 @@ impl Store { reader: impl BufRead, format: DatasetFormat, base_iri: Option<&str>, - ) -> Result<(), io::Error> { + ) -> io::Result<()> { load_dataset(&self.storage, reader, format, base_iri)?; Ok(()) } @@ -359,7 +359,7 @@ impl Store { /// This method is optimized for performances and is not atomic. /// It might leave the store in a bad state if a crash happens during the insertion. /// Use a (memory greedy) [transaction](Store::transaction()) if you do not want that. - pub fn insert<'a>(&self, quad: impl Into>) -> Result { + pub fn insert<'a>(&self, quad: impl Into>) -> io::Result { let quad = self.storage.encode_quad(quad.into())?; self.storage.insert(&quad) } @@ -371,7 +371,7 @@ impl Store { /// This method is optimized for performances and is not atomic. /// It might leave the store in a bad state if a crash happens during the removal. /// Use a (memory greedy) [transaction](Store::transaction()) if you do not want that. - pub fn remove<'a>(&self, quad: impl Into>) -> Result { + pub fn remove<'a>(&self, quad: impl Into>) -> io::Result { let quad = EncodedQuad::from(quad.into()); self.storage.remove(&quad) } @@ -399,7 +399,7 @@ impl Store { writer: impl Write, format: GraphFormat, from_graph_name: impl Into>, - ) -> Result<(), io::Error> { + ) -> io::Result<()> { dump_graph( self.quads_for_pattern(None, None, None, Some(from_graph_name.into())) .map(|q| Ok(q?.into())), @@ -424,7 +424,7 @@ impl Store { /// assert_eq!(file, buffer.as_slice()); /// # std::io::Result::Ok(()) /// ``` - pub fn dump_dataset(&self, writer: impl Write, format: DatasetFormat) -> Result<(), io::Error> { + pub fn dump_dataset(&self, writer: impl Write, format: DatasetFormat) -> io::Result<()> { dump_dataset(self.iter(), writer, format) } @@ -465,7 +465,7 @@ impl Store { pub fn contains_named_graph<'a>( &self, graph_name: impl Into>, - ) -> Result { + ) -> io::Result { let graph_name = EncodedTerm::from(graph_name.into()); self.storage.contains_named_graph(&graph_name) } @@ -488,7 +488,7 @@ impl Store { pub fn insert_named_graph<'a>( &self, graph_name: impl Into>, - ) -> Result { + ) -> io::Result { let graph_name = self.storage.encode_named_or_blank_node(graph_name.into())?; self.storage.insert_named_graph(&graph_name) } @@ -511,10 +511,7 @@ impl Store { /// assert_eq!(1, store.named_graphs().count()); /// # Result::<_,Box>::Ok(()) /// ``` - pub fn clear_graph<'a>( - &self, - graph_name: impl Into>, - ) -> Result<(), io::Error> { + pub fn clear_graph<'a>(&self, graph_name: impl Into>) -> io::Result<()> { let graph_name = EncodedTerm::from(graph_name.into()); self.storage.clear_graph(&graph_name) } @@ -542,7 +539,7 @@ impl Store { pub fn remove_named_graph<'a>( &self, graph_name: impl Into>, - ) -> Result { + ) -> io::Result { let graph_name = EncodedTerm::from(graph_name.into()); self.storage.remove_named_graph(&graph_name) } @@ -564,7 +561,7 @@ impl Store { /// assert!(store.is_empty()); /// # Result::<_,Box>::Ok(()) /// ``` - pub fn clear(&self) -> Result<(), io::Error> { + pub fn clear(&self) -> io::Result<()> { self.storage.clear() } @@ -574,7 +571,7 @@ impl Store { /// However, calling this method explicitly is still required for Windows and Android. /// /// An [async version](SledStore::flush_async) is also available. - pub fn flush(&self) -> Result<(), io::Error> { + pub fn flush(&self) -> io::Result<()> { self.storage.flush() } @@ -584,7 +581,7 @@ impl Store { /// However, calling this method explicitly is still required for Windows and Android. /// /// A [sync version](SledStore::flush) is also available. - pub async fn flush_async(&self) -> Result<(), io::Error> { + pub async fn flush_async(&self) -> io::Result<()> { self.storage.flush_async().await } } @@ -740,9 +737,9 @@ pub struct QuadIter { } impl Iterator for QuadIter { - type Item = Result; + type Item = io::Result; - fn next(&mut self) -> Option> { + fn next(&mut self) -> Option> { Some(match self.iter.next()? { Ok(quad) => self.storage.decode_quad(&quad).map_err(|e| e.into()), Err(error) => Err(error), @@ -757,9 +754,9 @@ pub struct GraphNameIter { } impl Iterator for GraphNameIter { - type Item = Result; + type Item = io::Result; - fn next(&mut self) -> Option> { + fn next(&mut self) -> Option> { Some( self.iter.next()?.and_then(|graph_name| { Ok(self.store.storage.decode_named_or_blank_node(&graph_name)?) @@ -773,7 +770,7 @@ impl Iterator for GraphNameIter { } #[test] -fn store() -> Result<(), io::Error> { +fn store() -> io::Result<()> { use crate::model::*; let main_s = Subject::from(BlankNode::default());