Simplifies Rio error handling

pull/10/head
Tpt 7 years ago
parent 5c90fab6cc
commit 4cae58df03
  1. 7
      src/rio/mod.rs
  2. 2
      src/rio/ntriples/mod.rs
  3. 10
      src/rio/turtle/mod.rs

@ -1,5 +1,6 @@
use std::error::Error;
use std::fmt;
use std::io;
pub mod ntriples;
pub mod turtle;
@ -22,6 +23,12 @@ impl RioError {
}
}
impl From<io::Error> for RioError {
fn from(error: io::Error) -> Self {
RioError::new(error)
}
}
impl fmt::Display for RioError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.error.fmt(f)

@ -19,6 +19,6 @@ pub fn read_ntriples<'a, R: Read + 'a>(source: R) -> impl Iterator<Item = RioRes
Ok(triple) => Some(Ok(triple?)),
Err(error) => Some(Err(RioError::new(error))),
},
Err(error) => Some(Err(RioError::new(error))),
Err(error) => Some(Err(error.into())),
})
}

@ -36,13 +36,13 @@ pub fn read_turtle<'a, R: Read + 'a>(
cur_subject: Vec::default(),
cur_predicate: Vec::default(),
};
let mut string_buffer = String::default();
let mut triple_buffer = Vec::default();
match BufReader::new(source).read_to_string(&mut string_buffer) {
Ok(_) => match grammar::turtleDoc(&string_buffer, &mut state, &mut triple_buffer) {
let mut string_buffer = String::default();
BufReader::new(source).read_to_string(&mut string_buffer)?;
match grammar::turtleDoc(&string_buffer, &mut state, &mut triple_buffer) {
Ok(_) => Ok(triple_buffer.into_iter()),
Err(error) => Err(RioError::new(error)),
},
Err(error) => Err(RioError::new(error)),
}
}

Loading…
Cancel
Save