markab_parser/and_parser/
error.rs1use crate::{
2 and_parser::AndParserRequirement,
3 Error,
4 Parser,
5};
6use std::fmt::{
7 Formatter,
8 Result as FmtResult,
9};
10
11#[derive(Debug)]
12pub struct AndParserError<'a, P>
13where
14 P: Parser<'a>,
15{
16 from: usize,
17 requirement: AndParserRequirement<'a, P>,
18 cause: P::Error,
19}
20
21impl<'a, P> AndParserError<'a, P>
22where
23 P: Parser<'a>,
24{
25 pub fn new(from: usize, requirement: AndParserRequirement<'a, P>, cause: P::Error) -> Self
26 {
27 Self {
28 from,
29 requirement,
30 cause,
31 }
32 }
33}
34
35impl<'a, P> Error for AndParserError<'a, P>
36where
37 P: Parser<'a>,
38{
39 fn from(&self, f: &mut Formatter) -> FmtResult
40 {
41 write!(f, "{}", self.from)
42 }
43
44 fn requirement(&self, f: &mut Formatter) -> FmtResult
45 {
46 write!(f, "{}", self.requirement)
47 }
48
49 fn result(&self, f: &mut Formatter) -> FmtResult
50 {
51 write!(f, "failed to parse")
52 }
53
54 fn causes(&self, f: &mut Formatter, depth: usize) -> FmtResult
55 {
56 self.cause.print(f, depth)
57 }
58}