Uses std::io::Result where relevant

pull/171/head
Tpt 3 years ago
parent 3307ec160e
commit c18281183a
  1. 16
      lib/src/io/read.rs
  2. 12
      lib/src/io/write.rs
  3. 10
      lib/src/model/dataset.rs
  4. 4
      lib/src/model/graph.rs
  5. 4
      lib/src/sparql/csv_results.rs
  6. 8
      lib/src/sparql/json_results.rs
  7. 5
      lib/src/sparql/model.rs
  8. 2
      lib/src/sparql/xml_results.rs
  9. 26
      lib/src/storage/binary_encoder.rs
  10. 8
      lib/src/storage/io.rs
  11. 54
      lib/src/storage/mod.rs
  12. 45
      lib/src/store.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<R: BufRead>(&self, reader: R) -> Result<TripleReader<R>, io::Error> {
pub fn read_triples<R: BufRead>(&self, reader: R) -> io::Result<TripleReader<R>> {
Ok(TripleReader {
mapper: RioMapper::default(),
parser: match self.format {
@ -113,9 +113,9 @@ enum TripleReaderKind<R: BufRead> {
}
impl<R: BufRead> Iterator for TripleReader<R> {
type Item = Result<Triple, io::Error>;
type Item = io::Result<Triple>;
fn next(&mut self) -> Option<Result<Triple, io::Error>> {
fn next(&mut self) -> Option<io::Result<Triple>> {
loop {
if let Some(r) = self.buffer.pop() {
return Some(Ok(r));
@ -143,7 +143,7 @@ impl<R: BufRead> TripleReader<R> {
parser: &mut P,
buffer: &mut Vec<Triple>,
mapper: &mut RioMapper,
) -> Option<Result<(), io::Error>>
) -> Option<io::Result<()>>
where
io::Error: From<P::Error>,
{
@ -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<R: BufRead>(&self, reader: R) -> Result<QuadReader<R>, io::Error> {
pub fn read_quads<R: BufRead>(&self, reader: R) -> io::Result<QuadReader<R>> {
Ok(QuadReader {
mapper: RioMapper::default(),
parser: match self.format {
@ -257,9 +257,9 @@ enum QuadReaderKind<R: BufRead> {
}
impl<R: BufRead> Iterator for QuadReader<R> {
type Item = Result<Quad, io::Error>;
type Item = io::Result<Quad>;
fn next(&mut self) -> Option<Result<Quad, io::Error>> {
fn next(&mut self) -> Option<io::Result<Quad>> {
loop {
if let Some(r) = self.buffer.pop() {
return Some(Ok(r));
@ -284,7 +284,7 @@ impl<R: BufRead> QuadReader<R> {
parser: &mut P,
buffer: &mut Vec<Quad>,
mapper: &mut RioMapper,
) -> Option<Result<(), io::Error>>
) -> Option<io::Result<()>>
where
io::Error: From<P::Error>,
{

@ -43,7 +43,7 @@ impl GraphSerializer {
}
/// Returns a `TripleWriter` allowing writing triples into the given [`Write`](std::io::Write) implementation
pub fn triple_writer<W: Write>(&self, writer: W) -> Result<TripleWriter<W>, io::Error> {
pub fn triple_writer<W: Write>(&self, writer: W) -> io::Result<TripleWriter<W>> {
Ok(TripleWriter {
formatter: match self.format {
GraphFormat::NTriples => TripleWriterKind::NTriples(NTriplesFormatter::new(writer)),
@ -88,7 +88,7 @@ enum TripleWriterKind<W: Write> {
impl<W: Write> TripleWriter<W> {
/// Writes a triple
pub fn write<'a>(&mut self, triple: impl Into<TripleRef<'a>>) -> Result<(), io::Error> {
pub fn write<'a>(&mut self, triple: impl Into<TripleRef<'a>>) -> io::Result<()> {
let triple = triple.into();
match &mut self.formatter {
TripleWriterKind::NTriples(formatter) => formatter.format(&triple.into())?,
@ -99,7 +99,7 @@ impl<W: Write> TripleWriter<W> {
}
/// 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<W: Write>(&self, writer: W) -> Result<QuadWriter<W>, io::Error> {
pub fn quad_writer<W: Write>(&self, writer: W) -> io::Result<QuadWriter<W>> {
Ok(QuadWriter {
formatter: match self.format {
DatasetFormat::NQuads => QuadWriterKind::NQuads(NQuadsFormatter::new(writer)),
@ -188,7 +188,7 @@ enum QuadWriterKind<W: Write> {
impl<W: Write> QuadWriter<W> {
/// Writes a quad
pub fn write<'a>(&mut self, quad: impl Into<QuadRef<'a>>) -> Result<(), io::Error> {
pub fn write<'a>(&mut self, quad: impl Into<QuadRef<'a>>) -> io::Result<()> {
let quad = quad.into();
match &mut self.formatter {
QuadWriterKind::NQuads(formatter) => formatter.format(&quad.into())?,
@ -198,7 +198,7 @@ impl<W: Write> QuadWriter<W> {
}
/// 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()?,

@ -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<dyn std::error::Error>>::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<dyn std::error::Error>>::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<dyn std::error::Error>>::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)
}
}

@ -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<dyn std::error::Error>>::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)
}

@ -178,7 +178,7 @@ fn write_tsv_term<'a>(term: impl Into<TermRef<'a>>, sink: &mut impl Write) -> io
}
}
pub fn read_tsv_results(mut source: impl BufRead + 'static) -> Result<QueryResults, io::Error> {
pub fn read_tsv_results(mut source: impl BufRead + 'static) -> io::Result<QueryResults> {
let mut buffer = String::new();
// We read the header
@ -192,7 +192,7 @@ pub fn read_tsv_results(mut source: impl BufRead + 'static) -> Result<QueryResul
let variables = buffer
.split('\t')
.map(|v| Variable::from_str(v.trim()).map_err(invalid_data_error))
.collect::<Result<Vec<_>, io::Error>>()?;
.collect::<io::Result<Vec<_>>>()?;
Ok(QueryResults::Solutions(QuerySolutionIter::new(
Rc::new(variables),

@ -115,7 +115,7 @@ fn write_json_term(
Ok(())
}
pub fn read_json_results(source: impl BufRead + 'static) -> Result<QueryResults, io::Error> {
pub fn read_json_results(source: impl BufRead + 'static) -> io::Result<QueryResults> {
let mut reader = JsonReader::from_reader(source);
let mut buffer = Vec::default();
let mut variables = None;
@ -423,8 +423,7 @@ impl<R: BufRead> ResultsIterator<R> {
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<R: BufRead> ResultsIterator<R> {
_ => {
return Err(invalid_data_error(
"The 'predicate' value should be a uri",
)
.into())
))
}
},
object.ok_or_else(|| {

@ -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<Self, io::Error> {
pub fn read(reader: impl BufRead + 'static, format: QueryResultsFormat) -> io::Result<Self> {
match format {
QueryResultsFormat::Xml => read_xml_results(reader),
QueryResultsFormat::Json => read_json_results(reader),

@ -183,7 +183,7 @@ fn write_xml_term(
Ok(())
}
pub fn read_xml_results(source: impl BufRead + 'static) -> Result<QueryResults, io::Error> {
pub fn read_xml_results(source: impl BufRead + 'static) -> io::Result<QueryResults> {
enum State {
Start,
Sparql,

@ -63,7 +63,7 @@ pub enum QuadEncoding {
}
impl QuadEncoding {
pub fn decode(self, buffer: &[u8]) -> Result<EncodedQuad, io::Error> {
pub fn decode(self, buffer: &[u8]) -> io::Result<EncodedQuad> {
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<EncodedTerm, io::Error> {
pub fn decode_term(buffer: &[u8]) -> io::Result<EncodedTerm> {
Cursor::new(&buffer).read_term()
}
pub trait TermReader {
fn read_term(&mut self) -> Result<EncodedTerm, io::Error>;
fn read_term(&mut self) -> io::Result<EncodedTerm>;
fn read_spog_quad(&mut self) -> Result<EncodedQuad, io::Error> {
fn read_spog_quad(&mut self) -> io::Result<EncodedQuad> {
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<EncodedQuad, io::Error> {
fn read_posg_quad(&mut self) -> io::Result<EncodedQuad> {
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<EncodedQuad, io::Error> {
fn read_ospg_quad(&mut self) -> io::Result<EncodedQuad> {
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<EncodedQuad, io::Error> {
fn read_gspo_quad(&mut self) -> io::Result<EncodedQuad> {
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<EncodedQuad, io::Error> {
fn read_gpos_quad(&mut self) -> io::Result<EncodedQuad> {
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<EncodedQuad, io::Error> {
fn read_gosp_quad(&mut self) -> io::Result<EncodedQuad> {
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<EncodedQuad, io::Error> {
fn read_dspo_quad(&mut self) -> io::Result<EncodedQuad> {
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<EncodedQuad, io::Error> {
fn read_dpos_quad(&mut self) -> io::Result<EncodedQuad> {
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<EncodedQuad, io::Error> {
fn read_dosp_quad(&mut self) -> io::Result<EncodedQuad> {
let object = self.read_term()?;
let subject = self.read_term()?;
let predicate = self.read_term()?;
@ -202,7 +202,7 @@ pub trait TermReader {
}
impl<R: Read> TermReader for R {
fn read_term(&mut self) -> Result<EncodedTerm, io::Error> {
fn read_term(&mut self) -> io::Result<EncodedTerm> {
let mut type_buffer = [0];
self.read_exact(&mut type_buffer)?;
match type_buffer[0] {

@ -60,10 +60,10 @@ where
}
pub fn dump_graph(
triples: impl Iterator<Item = Result<Triple, io::Error>>,
triples: impl Iterator<Item = io::Result<Triple>>,
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<Item = Result<Quad, io::Error>>,
quads: impl Iterator<Item = io::Result<Quad>>,
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?)?;

@ -43,15 +43,15 @@ pub struct Storage {
}
impl Storage {
pub fn new() -> Result<Self, std::io::Error> {
pub fn new() -> std::io::Result<Self> {
Self::do_open(&Config::new().temporary(true))
}
pub fn open(path: &Path) -> Result<Self, std::io::Error> {
pub fn open(path: &Path) -> std::io::Result<Self> {
Self::do_open(&Config::new().path(path))
}
fn do_open(config: &Config) -> Result<Self, std::io::Error> {
fn do_open(config: &Config) -> std::io::Result<Self> {
let db = config.open()?;
let this = Self {
default: db.clone(),
@ -95,7 +95,7 @@ impl Storage {
}
}
fn ensure_version(&self) -> Result<u64, std::io::Error> {
fn ensure_version(&self) -> std::io::Result<u64> {
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<bool, std::io::Error> {
pub fn contains(&self, quad: &EncodedQuad) -> std::io::Result<bool> {
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<bool, std::io::Error> {
pub fn contains_named_graph(&self, graph_name: &EncodedTerm) -> std::io::Result<bool> {
Ok(self.graphs.contains_key(&encode_term(graph_name))?)
}
@ -457,7 +457,7 @@ impl Storage {
}
}
pub fn insert(&self, quad: &EncodedQuad) -> Result<bool, std::io::Error> {
pub fn insert(&self, quad: &EncodedQuad) -> std::io::Result<bool> {
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<bool, std::io::Error> {
pub fn remove(&self, quad: &EncodedQuad) -> std::io::Result<bool> {
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<bool, std::io::Error> {
pub fn insert_named_graph(&self, graph_name: &EncodedTerm) -> std::io::Result<bool> {
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<bool, std::io::Error> {
pub fn remove_named_graph(&self, graph_name: &EncodedTerm) -> std::io::Result<bool> {
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<Option<String>, std::io::Error> {
pub fn get_str(&self, key: &StrHash) -> std::io::Result<Option<String>> {
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<bool, std::io::Error> {
pub fn contains_str(&self, key: &StrHash) -> std::io::Result<bool> {
Ok(self.id2str.contains_key(key.to_be_bytes())?)
}
pub fn insert_str(&self, key: &StrHash, value: &str) -> Result<bool, std::io::Error> {
pub fn insert_str(&self, key: &StrHash, value: &str) -> std::io::Result<bool> {
Ok(self.id2str.insert(key.to_be_bytes(), value)?.is_none())
}
}
@ -652,9 +652,9 @@ impl ChainedDecodingQuadIterator {
}
impl Iterator for ChainedDecodingQuadIterator {
type Item = Result<EncodedQuad, std::io::Error>;
type Item = std::io::Result<EncodedQuad>;
fn next(&mut self) -> Option<Result<EncodedQuad, std::io::Error>> {
fn next(&mut self) -> Option<std::io::Result<EncodedQuad>> {
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<EncodedQuad, std::io::Error>;
type Item = std::io::Result<EncodedQuad>;
fn next(&mut self) -> Option<Result<EncodedQuad, std::io::Error>> {
fn next(&mut self) -> Option<std::io::Result<EncodedQuad>> {
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<EncodedTerm, std::io::Error>;
type Item = std::io::Result<EncodedTerm>;
fn next(&mut self) -> Option<Result<EncodedTerm, std::io::Error>> {
fn next(&mut self) -> Option<std::io::Result<EncodedTerm>> {
Some(match self.iter.next()? {
Ok((encoded, _)) => decode_term(&encoded),
Err(error) => Err(error.into()),
@ -1002,17 +1002,17 @@ impl<T> From<ConflictableTransactionError<T>> for Sled2ConflictableTransactionEr
impl StrLookup for Storage {
type Error = std::io::Error;
fn get_str(&self, key: &StrHash) -> Result<Option<String>, std::io::Error> {
fn get_str(&self, key: &StrHash) -> std::io::Result<Option<String>> {
self.get_str(key)
}
fn contains_str(&self, key: &StrHash) -> Result<bool, std::io::Error> {
fn contains_str(&self, key: &StrHash) -> std::io::Result<bool> {
self.contains_str(key)
}
}
impl StrContainer for Storage {
fn insert_str(&self, key: &StrHash, value: &str) -> Result<bool, std::io::Error> {
fn insert_str(&self, key: &StrHash, value: &str) -> std::io::Result<bool> {
self.insert_str(key, value)
}
}

@ -86,14 +86,14 @@ pub struct Store {
impl Store {
/// Creates a temporary [`Store`]() that will be deleted after drop.
pub fn new() -> Result<Self, io::Error> {
pub fn new() -> io::Result<Self> {
Ok(Self {
storage: Storage::new()?,
})
}
/// Opens a [`Store`]() and creates it if it does not exist yet.
pub fn open(path: impl AsRef<Path>) -> Result<Self, io::Error> {
pub fn open(path: impl AsRef<Path>) -> io::Result<Self> {
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<QuadRef<'a>>) -> Result<bool, io::Error> {
pub fn contains<'a>(&self, quad: impl Into<QuadRef<'a>>) -> io::Result<bool> {
let quad = EncodedQuad::from(quad.into());
self.storage.contains(&quad)
}
@ -303,7 +303,7 @@ impl Store {
format: GraphFormat,
to_graph_name: impl Into<GraphNameRef<'a>>,
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<QuadRef<'a>>) -> Result<bool, io::Error> {
pub fn insert<'a>(&self, quad: impl Into<QuadRef<'a>>) -> io::Result<bool> {
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<QuadRef<'a>>) -> Result<bool, io::Error> {
pub fn remove<'a>(&self, quad: impl Into<QuadRef<'a>>) -> io::Result<bool> {
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<GraphNameRef<'a>>,
) -> 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<NamedOrBlankNodeRef<'a>>,
) -> Result<bool, io::Error> {
) -> io::Result<bool> {
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<NamedOrBlankNodeRef<'a>>,
) -> Result<bool, io::Error> {
) -> io::Result<bool> {
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<dyn std::error::Error>>::Ok(())
/// ```
pub fn clear_graph<'a>(
&self,
graph_name: impl Into<GraphNameRef<'a>>,
) -> Result<(), io::Error> {
pub fn clear_graph<'a>(&self, graph_name: impl Into<GraphNameRef<'a>>) -> 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<NamedOrBlankNodeRef<'a>>,
) -> Result<bool, io::Error> {
) -> io::Result<bool> {
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<dyn std::error::Error>>::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<Quad, io::Error>;
type Item = io::Result<Quad>;
fn next(&mut self) -> Option<Result<Quad, io::Error>> {
fn next(&mut self) -> Option<io::Result<Quad>> {
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<NamedOrBlankNode, io::Error>;
type Item = io::Result<NamedOrBlankNode>;
fn next(&mut self) -> Option<Result<NamedOrBlankNode, io::Error>> {
fn next(&mut self) -> Option<io::Result<NamedOrBlankNode>> {
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());

Loading…
Cancel
Save