mirror of
https://codeberg.org/icewind/tf-log-parser.git
synced 2026-11-30 04:40:47 +01:00
more fine grained line skip
This commit is contained in:
parent
ec62be0b38
commit
8e61628c22
3 changed files with 63 additions and 44 deletions
54
src/error.rs
Normal file
54
src/error.rs
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
use crate::event::GameEventError;
|
||||
use crate::SubjectError;
|
||||
use std::num::ParseIntError;
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum Error {
|
||||
#[error("Malformed logfile")]
|
||||
Malformed,
|
||||
#[error("Incomplete logfile")]
|
||||
Incomplete,
|
||||
#[error("Incomplete logfile")]
|
||||
Skip,
|
||||
#[error("Malformed subject: {0}")]
|
||||
Subject(Box<SubjectError>),
|
||||
#[error("{0}")]
|
||||
MalformedEvent(Box<GameEventError>),
|
||||
}
|
||||
|
||||
impl From<SubjectError> for Error {
|
||||
fn from(value: SubjectError) -> Self {
|
||||
Error::Subject(Box::new(value))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<GameEventError> for Error {
|
||||
fn from(value: GameEventError) -> Self {
|
||||
Error::MalformedEvent(Box::new(value))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ParseIntError> for Error {
|
||||
fn from(_: ParseIntError) -> Self {
|
||||
Error::Malformed
|
||||
}
|
||||
}
|
||||
|
||||
pub type Result<O, E = Error> = std::result::Result<O, E>;
|
||||
|
||||
#[doc(hidden)]
|
||||
pub type IResult<'a, O, E = Error> = std::result::Result<(&'a str, O), E>;
|
||||
|
||||
pub trait ResultExt: Sized {
|
||||
fn skip_incomplete(self) -> Self;
|
||||
}
|
||||
|
||||
impl<T> ResultExt for Result<T> {
|
||||
fn skip_incomplete(self) -> Self {
|
||||
self.map_err(|e| match e {
|
||||
Error::Incomplete => Error::Skip,
|
||||
e => e,
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue