Remove From<pest::Error> for MatrixMarketError

We want pest to remain an internal implementation detail, so it should
not leak into the public API.
This commit is contained in:
Andreas Longva 2021-12-01 11:33:03 +01:00
parent 4d0f401882
commit 93f3d60005
1 changed files with 9 additions and 6 deletions

View File

@ -298,13 +298,14 @@ impl fmt::Display for MatrixMarketError {
impl std::error::Error for MatrixMarketError {}
impl<T: fmt::Debug + std::hash::Hash + std::marker::Copy + Ord> From<pest::error::Error<T>>
for MatrixMarketError
{
fn from(err: pest::error::Error<T>) -> Self {
impl MatrixMarketError {
fn from_pest_error<T>(error: pest::error::Error<T>) -> Self
where
T: fmt::Debug + std::hash::Hash + std::marker::Copy + Ord
{
Self::from_kind_and_message(
MatrixMarketErrorKind::ParsingError,
format!("Can't parse the data.\n Error: {}", err),
format!("Can't parse the data.\n Error: {}", error),
)
}
}
@ -756,7 +757,9 @@ where
T: MatrixMarketScalar,
{
// unwrap() in this function are guaranteed by parsing the data
let file = MatrixMarketParser::parse(Rule::Document, data)?.next().unwrap();
let file = MatrixMarketParser::parse(Rule::Document, data)
.map_err(MatrixMarketError::from_pest_error)?
.next().unwrap();
let mut rows: Vec<usize> = Vec::new();
let mut cols: Vec<usize> = Vec::new();