1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use std::fmt::Display;

use crate::{Error, LocatedError};

/// Error type for infallible generator.
///
/// You should never return this error in generating step if choose this as the Error type of your Generator.
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct GeneratorInfallible;

impl Display for GeneratorInfallible {
    fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        panic!("infallible generator emitted a error, please report this bug")
    }
}

impl LocatedError for GeneratorInfallible {
    fn location(&self) -> (usize, usize) {
        panic!("infallible generator emitted a error, please report this bug")
    }
}

impl<'a> From<GeneratorInfallible> for Error<'a, GeneratorInfallible> {
    fn from(e: GeneratorInfallible) -> Self {
        Error::Gen(e)
    }
}