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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use std::{
    error::Error,
    fmt::{Debug, Display},
};

use crate::LocatedError;

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

impl GeneratorInfallible {
    fn panic() -> ! {
        panic!("infallible generator emitted a error, please report this as bug")
    }
}

impl Debug for GeneratorInfallible {
    fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        GeneratorInfallible::panic()
    }
}

impl Display for GeneratorInfallible {
    fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        GeneratorInfallible::panic()
    }
}

impl Error for GeneratorInfallible {}

impl LocatedError for GeneratorInfallible {
    fn location(&self) -> (usize, usize) {
        GeneratorInfallible::panic()
    }
}

impl<'a> From<GeneratorInfallible> for crate::Error<'a, GeneratorInfallible> {
    fn from(_e: GeneratorInfallible) -> Self {
        GeneratorInfallible::panic()
    }
}