From d649c218c1bfe556b70e8ff6f1b95bb6d74c2d0c Mon Sep 17 00:00:00 2001 From: Philipp A Date: Sun, 2 Dec 2018 15:37:28 +0100 Subject: Move block conversions to submodule --- src/parser/pair_ext_parse.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/parser/pair_ext_parse.rs (limited to 'src/parser/pair_ext_parse.rs') diff --git a/src/parser/pair_ext_parse.rs b/src/parser/pair_ext_parse.rs new file mode 100644 index 0000000..2ce642a --- /dev/null +++ b/src/parser/pair_ext_parse.rs @@ -0,0 +1,18 @@ +use std::str::FromStr; + +use pest::iterators::Pair; +use pest::error::{Error,ErrorVariant}; + + +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: T::Err| { + let var: ErrorVariant = ErrorVariant::CustomError { message: e.to_string() }; + Error::new_from_span(var, self.as_span()) + }) + } +} -- cgit v1.2.3