Skip to main content

oneline_template/template/syntax/
expected_token_error.rs

1use std::error::Error;
2use std::fmt;
3
4/// Wrong input was passed when some token is expected.
5#[derive(Debug)]
6pub struct ExpectedTokenError {
7    token: String,
8    input: String,
9}
10
11impl ExpectedTokenError {
12    pub (crate) fn new(token: impl Into<String>, input: impl Into<String>) -> ExpectedTokenError {
13        return ExpectedTokenError {
14            token: token.into(),
15            input: input.into(),
16        }
17    }
18}
19
20impl fmt::Display for ExpectedTokenError {
21    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22        write!(f, "Expected token `{}` in `{}`", self.token, self.input)
23    }
24}
25
26impl Error for ExpectedTokenError {}