mirror of
https://codeberg.org/icewind/tf-log-parser.git
synced 2026-06-03 18:24:09 +02:00
iresult->result in more places
This commit is contained in:
parent
3ad9ebafd7
commit
1522bd2648
6 changed files with 20 additions and 25 deletions
|
|
@ -1,6 +1,6 @@
|
|||
use crate::event::{param_parse_with, parse_field, ParamIter};
|
||||
use crate::raw_event::RawSubject;
|
||||
use crate::{Error, Event, IResult};
|
||||
use crate::{Error, Event, Result};
|
||||
|
||||
use crate::parsing::{skip, take_until};
|
||||
|
||||
|
|
@ -30,12 +30,12 @@ pub struct TournamentModeStartedEvent<'a> {
|
|||
}
|
||||
|
||||
impl<'a> Event<'a> for TournamentModeStartedEvent<'a> {
|
||||
fn parse(input: &'a str) -> IResult<Self> {
|
||||
fn parse(input: &'a str) -> Result<Self> {
|
||||
let input = skip(input, "\nBlue Team: ".len())?;
|
||||
let (input, blue) = take_until(input, b'\n');
|
||||
let input = skip(input, "\nRed Team: ".len())?;
|
||||
let (input, red) = take_until(input, b'\n');
|
||||
Ok((input, TournamentModeStartedEvent { blue, red }))
|
||||
let (_, red) = take_until(input, b'\n');
|
||||
Ok(TournamentModeStartedEvent { blue, red })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -56,7 +56,7 @@ pub struct PointCapturedEvent<'a> {
|
|||
}
|
||||
|
||||
impl<'a> Event<'a> for PointCapturedEvent<'a> {
|
||||
fn parse(input: &'a str) -> IResult<Self> {
|
||||
fn parse(input: &'a str) -> Result<Self> {
|
||||
let mut cp = Default::default();
|
||||
let mut cp_name = Default::default();
|
||||
let mut num_cappers = Default::default();
|
||||
|
|
@ -94,15 +94,12 @@ impl<'a> Event<'a> for PointCapturedEvent<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
Ok((
|
||||
input,
|
||||
PointCapturedEvent {
|
||||
cp,
|
||||
num_cappers,
|
||||
cp_name,
|
||||
players,
|
||||
},
|
||||
))
|
||||
Ok(PointCapturedEvent {
|
||||
cp,
|
||||
num_cappers,
|
||||
cp_name,
|
||||
players,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::event::{param_parse_with, parse_field, ParamIter};
|
||||
use crate::raw_event::RawSubject;
|
||||
use crate::{Event, IResult};
|
||||
use crate::{Event, Result};
|
||||
|
||||
#[derive(Debug, Event)]
|
||||
pub struct HealedEvent<'a> {
|
||||
|
|
|
|||
|
|
@ -29,22 +29,21 @@ trait GameEventErrTrait<T> {
|
|||
fn with_raw(self, raw: &RawEvent) -> Result<T, GameEventError>;
|
||||
}
|
||||
|
||||
impl<'a, T> GameEventErrTrait<T> for IResult<'a, T> {
|
||||
impl<'a, T> GameEventErrTrait<T> for Result<T> {
|
||||
fn with_raw(self, raw: &RawEvent) -> Result<T, GameEventError> {
|
||||
self.map_err(|err| GameEventError::Error {
|
||||
err: Box::new(err),
|
||||
ty: raw.ty,
|
||||
params: raw.params.to_string(),
|
||||
})
|
||||
.map(|(_rest, t)| t)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Event<'a>: Sized + 'a {
|
||||
fn parse(input: &'a str) -> IResult<Self>;
|
||||
fn parse(input: &'a str) -> Result<Self>;
|
||||
}
|
||||
|
||||
fn parse_event<'a, T: Event<'a>>(input: &'a str) -> IResult<T> {
|
||||
fn parse_event<'a, T: Event<'a>>(input: &'a str) -> Result<T> {
|
||||
T::parse(input)
|
||||
}
|
||||
|
||||
|
|
@ -111,8 +110,8 @@ pub struct UnparsedEvent<'a> {
|
|||
}
|
||||
|
||||
impl<'a> Event<'a> for UnparsedEvent<'a> {
|
||||
fn parse(input: &'a str) -> IResult<Self> {
|
||||
Ok(("", UnparsedEvent { params: input }))
|
||||
fn parse(input: &'a str) -> Result<Self> {
|
||||
Ok(UnparsedEvent { params: input })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use crate::common::{Class, Team};
|
||||
use crate::event::{param_parse_with, parse_field, quoted, ParamIter};
|
||||
use crate::raw_event::RawSubject;
|
||||
use crate::{Error, Event, IResult};
|
||||
use crate::{Error, Event, Result};
|
||||
use std::net::SocketAddr;
|
||||
use std::num::NonZeroU32;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue