Skip to content

Commit

Permalink
Run rustfmt and clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
MattesWhite committed Dec 18, 2019
1 parent 2b3019a commit 79a1b62
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 43 deletions.
10 changes: 6 additions & 4 deletions sophia/src/parser/nq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use super::common::*;
use super::nt::{pair_to_term, PestNtqParser, Rule};
use crate::error::*;
use crate::quad::stream::*;
use crate::triple::stream::*;
use crate::term::Term;
use crate::triple::stream::*;

/// N-Quads parser configuration.
///
Expand Down Expand Up @@ -100,14 +100,16 @@ where
fn in_sink<TS: QuadSink>(
&mut self,
sink: &mut TS,
) -> StdResult<TS::Outcome, StreamError<Self::Error, TS::Error>>
{
) -> StdResult<TS::Outcome, StreamError<Self::Error, TS::Error>> {
for (lineidx, line) in (&mut self.bufread).lines().enumerate() {
let line = match line {
Ok(line) => line,
Err(ioerr) => {
let msg = format!("{}", ioerr);
return Err(SourceError(Error::with_chain(ioerr, make_parser_error(msg, lineidx)).into()));
return Err(SourceError(Error::with_chain(
ioerr,
make_parser_error(msg, lineidx),
)));
}
};
let trimmed = line.trim_start();
Expand Down
8 changes: 5 additions & 3 deletions sophia/src/parser/nt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,16 @@ where
fn in_sink<TS: TripleSink>(
&mut self,
sink: &mut TS,
) -> StdResult<TS::Outcome, StreamError<Self::Error, TS::Error>>
{
) -> StdResult<TS::Outcome, StreamError<Self::Error, TS::Error>> {
for (lineidx, line) in (&mut self.bufread).lines().enumerate() {
let line = match line {
Ok(line) => line,
Err(ioerr) => {
let msg = format!("{}", ioerr);
return Err(SourceError(Error::with_chain(ioerr, make_parser_error(msg, lineidx)).into()));
return Err(SourceError(Error::with_chain(
ioerr,
make_parser_error(msg, lineidx),
)));
}
};
let trimmed = line.trim_start();
Expand Down
64 changes: 35 additions & 29 deletions sophia/src/parser/rio_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,29 @@ where
fn in_sink<TS: TripleSink>(
&mut self,
sink: &mut TS,
) -> StdResult<TS::Outcome, StreamError<Error, TS::Error>>
{
) -> StdResult<TS::Outcome, StreamError<Error, TS::Error>> {
match self {
RioSource::Error(opt) => opt
.take()
.map(|e| Err(SourceError(Error::from(e).into())))
.unwrap_or_else(|| {
let message = "This parser has already failed".to_string();
let location = Location::Unknown;
Err(SourceError(Error::from(ErrorKind::ParserError(message, location)).into()))
Err(SourceError(
Error::from(ErrorKind::ParserError(message, location)).into(),
))
}),
RioSource::Parser(parser) => {
parser.parse_all(&mut |t| -> Result<()> {
sink.feed(&[
rio2refterm(t.subject.into()).unwrap(), // TODO handle error properly
rio2refterm(t.predicate.into()).unwrap(), // TODO handle error properly
rio2refterm(t.object).unwrap(), // TODO handle error properly
])
.map_err(TS::Error::into)
}).map_err(SourceError)?;
parser
.parse_all(&mut |t| -> Result<()> {
sink.feed(&[
rio2refterm(t.subject.into()).unwrap(), // TODO handle error properly
rio2refterm(t.predicate.into()).unwrap(), // TODO handle error properly
rio2refterm(t.object).unwrap(), // TODO handle error properly
])
.map_err(TS::Error::into)
})
.map_err(SourceError)?;
Ok(sink.finish().map_err(SinkError)?)
}
}
Expand All @@ -74,33 +77,36 @@ where
fn in_sink<TS: QuadSink>(
&mut self,
sink: &mut TS,
) -> StdResult<TS::Outcome, StreamError<Error, TS::Error>>
{
) -> StdResult<TS::Outcome, StreamError<Error, TS::Error>> {
match self {
RioSource::Error(opt) => opt
.take()
.map(|e| Err(SourceError(Error::from(e).into())))
.unwrap_or_else(|| {
let message = "This parser has already failed".to_string();
let location = Location::Unknown;
Err(SourceError(Error::from(ErrorKind::ParserError(message, location)).into()))
Err(SourceError(
Error::from(ErrorKind::ParserError(message, location)).into(),
))
}),
RioSource::Parser(parser) => {
parser.parse_all(&mut |q| -> Result<()> {
sink.feed(&(
[
rio2refterm(q.subject.into()).unwrap(), // TODO handle error properly
rio2refterm(q.predicate.into()).unwrap(), // TODO handle error properly
rio2refterm(q.object).unwrap(), // TODO handle error properly
],
if let Some(n) = q.graph_name {
Some(rio2refterm(n.into()).unwrap()) // TODO handle error properly
} else {
None
},
))
.map_err(TS::Error::into)
}).map_err(SourceError)?;
parser
.parse_all(&mut |q| -> Result<()> {
sink.feed(&(
[
rio2refterm(q.subject.into()).unwrap(), // TODO handle error properly
rio2refterm(q.predicate.into()).unwrap(), // TODO handle error properly
rio2refterm(q.object).unwrap(), // TODO handle error properly
],
if let Some(n) = q.graph_name {
Some(rio2refterm(n.into()).unwrap()) // TODO handle error properly
} else {
None
},
))
.map_err(TS::Error::into)
})
.map_err(SourceError)?;
Ok(sink.finish().map_err(SinkError)?)
}
}
Expand Down
11 changes: 4 additions & 7 deletions sophia/src/triple/stream/_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::error::Error;
/// or `Sink` failed.
///
/// # Conversion
///
///
/// Both variants `SourceError` and `SinkError` are public exported.
/// Consequently, `StreamError` can be constructed with `.map_err(SourceError)`
/// and `.map_err(SinkError)`.
Expand All @@ -26,9 +26,9 @@ where
SinkErr: 'static + Error,
{
#[error("Source failed: {0}")]
SourceError( #[source] SourceErr),
SourceError(#[source] SourceErr),
#[error("Sink failed: {0}")]
SinkError( #[source] SinkErr),
SinkError(#[source] SinkErr),
}

pub use self::StreamError::*;
Expand All @@ -55,7 +55,7 @@ where
}
}
/// Converts `StreamError` into an inner error.
pub fn inner_into<Err>(self) -> Err
pub fn inner_into<Err>(self) -> Err
where
SourceErr: 'static + Error + Into<Err>,
SinkErr: 'static + Error + Into<Err>,
Expand All @@ -65,7 +65,4 @@ where
SinkError(err) => err.into(),
}
}

}


0 comments on commit 79a1b62

Please sign in to comment.