mirror of
https://github.com/aljazceru/notedeck.git
synced 2025-12-18 00:54:21 +01:00
introduce TokenHandler
used for saving anything `TokenSerializable` to disk Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
@@ -4,6 +4,12 @@ pub struct UnexpectedToken<'fnd, 'exp> {
|
||||
pub found: &'fnd str,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct UnexpectedTokenOwned {
|
||||
pub expected: String,
|
||||
pub found: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ParseError<'a> {
|
||||
/// Not done parsing yet
|
||||
@@ -24,6 +30,34 @@ pub enum ParseError<'a> {
|
||||
EOF,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ParseErrorOwned {
|
||||
Incomplete,
|
||||
AltAllFailed,
|
||||
DecodeFailed,
|
||||
HexDecodeFailed,
|
||||
UnexpectedToken(UnexpectedTokenOwned),
|
||||
EOF,
|
||||
}
|
||||
|
||||
impl From<ParseError<'_>> for ParseErrorOwned {
|
||||
fn from(value: ParseError) -> Self {
|
||||
match value {
|
||||
ParseError::Incomplete => Self::Incomplete,
|
||||
ParseError::AltAllFailed => Self::AltAllFailed,
|
||||
ParseError::DecodeFailed => Self::DecodeFailed,
|
||||
ParseError::HexDecodeFailed => Self::HexDecodeFailed,
|
||||
ParseError::UnexpectedToken(unexpected_token) => {
|
||||
Self::UnexpectedToken(UnexpectedTokenOwned {
|
||||
expected: unexpected_token.expected.to_owned(),
|
||||
found: unexpected_token.found.to_owned(),
|
||||
})
|
||||
}
|
||||
ParseError::EOF => Self::EOF,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TokenWriter {
|
||||
delim: &'static str,
|
||||
tokens_written: usize,
|
||||
|
||||
Reference in New Issue
Block a user