doki_error/error_3rd/
for_pest.rs1use crate::DokiError;
2use pest::error::{Error, ErrorVariant};
3use std::fmt::Debug;
4
5impl<R> From<Error<R>> for DokiError
6where
7 R: Debug,
8{
9 fn from(e: Error<R>) -> Self {
10 let error = Self::from(e.variant);
11 error
12 }
13}
14
15impl<R> From<ErrorVariant<R>> for DokiError
16where
17 R: Debug,
18{
19 fn from(e: ErrorVariant<R>) -> Self {
20 let msg = match e {
21 ErrorVariant::ParsingError { positives, negatives } => {
22 format!("Positive attempts: {:?}\nNegative attempts: {:?}", positives, negatives)
23 }
24 ErrorVariant::CustomError { message } => message,
25 };
26 Self::syntax_error(msg)
27 }
28}