aboutsummaryrefslogtreecommitdiffstats
path: root/src/parser/pair_ext_parse.rs
diff options
context:
space:
mode:
authorPhilipp A2018-12-02 15:37:28 +0100
committerPhilipp A2018-12-02 15:37:28 +0100
commitd649c218c1bfe556b70e8ff6f1b95bb6d74c2d0c (patch)
treecd11b1207c8cf9e0e2b41424d2b35465cfcfe386 /src/parser/pair_ext_parse.rs
parent04e8c55fc345264deea85e23502e640ae6d6aea2 (diff)
downloadrust-rst-d649c218c1bfe556b70e8ff6f1b95bb6d74c2d0c.tar.bz2
Move block conversions to submodule
Diffstat (limited to 'src/parser/pair_ext_parse.rs')
-rw-r--r--src/parser/pair_ext_parse.rs18
1 files changed, 18 insertions, 0 deletions
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<R> where R: pest::RuleType {
+ fn parse<T, E>(&self) -> Result<T, Error<R>> where T: FromStr<Err = E>, E: ToString;
+}
+
+impl<'l, R> PairExt<R> for Pair<'l, R> where R: pest::RuleType {
+ fn parse<T, E>(&self) -> Result<T, Error<R>> where T: FromStr<Err = E>, E: ToString {
+ self.as_str().parse().map_err(|e: T::Err| {
+ let var: ErrorVariant<R> = ErrorVariant::CustomError { message: e.to_string() };
+ Error::new_from_span(var, self.as_span())
+ })
+ }
+}