use std::str::FromStr; use pest::error::{Error, ErrorVariant}; use pest::iterators::Pair; use pest::Span; pub trait PairExt where R: pest::RuleType, { fn parse(&self) -> Result>> where T: FromStr, E: ToString; } impl<'l, R> PairExt for Pair<'l, R> where R: pest::RuleType, { fn parse(&self) -> Result>> where T: FromStr, E: ToString, { self.as_str() .parse() .map_err(|e| to_parse_error(self.as_span(), &e)) } } pub(crate) fn to_parse_error(span: Span, e: &E) -> Box> where E: ToString, R: pest::RuleType, { let var: ErrorVariant = ErrorVariant::CustomError { message: e.to_string(), }; Box::new(Error::new_from_span(var, span)) }