mirror of
https://codeberg.org/icewind/tf-log-parser.git
synced 2026-06-03 10:14:10 +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
|
|
@ -75,14 +75,14 @@ impl Derivable for Event {
|
||||||
|
|
||||||
Ok(
|
Ok(
|
||||||
quote_spanned!(span => impl #impl_generics Event<#lifetime> for #struct_ident #ty_generics #where_clause {
|
quote_spanned!(span => impl #impl_generics Event<#lifetime> for #struct_ident #ty_generics #where_clause {
|
||||||
fn parse(input: & #lifetime str) -> IResult<Self> {
|
fn parse(input: & #lifetime str) -> Result<Self> {
|
||||||
#(#required_fields)*
|
#(#required_fields)*
|
||||||
|
|
||||||
#initiator
|
#initiator
|
||||||
|
|
||||||
#update
|
#update
|
||||||
|
|
||||||
Ok(("", event))
|
Ok(event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,6 @@ impl Derivable for Events {
|
||||||
Ok(
|
Ok(
|
||||||
quote_spanned!(span => impl #impl_generics #enum_ident #ty_generics #where_clause {
|
quote_spanned!(span => impl #impl_generics #enum_ident #ty_generics #where_clause {
|
||||||
pub fn parse(raw: &RawEvent<'a>) -> Result<Self, GameEventError> {
|
pub fn parse(raw: &RawEvent<'a>) -> Result<Self, GameEventError> {
|
||||||
dbg!(raw);
|
|
||||||
Ok(match raw.ty {
|
Ok(match raw.ty {
|
||||||
#(#variants)*
|
#(#variants)*
|
||||||
_ => {
|
_ => {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::event::{param_parse_with, parse_field, ParamIter};
|
use crate::event::{param_parse_with, parse_field, ParamIter};
|
||||||
use crate::raw_event::RawSubject;
|
use crate::raw_event::RawSubject;
|
||||||
use crate::{Error, Event, IResult};
|
use crate::{Error, Event, Result};
|
||||||
|
|
||||||
use crate::parsing::{skip, take_until};
|
use crate::parsing::{skip, take_until};
|
||||||
|
|
||||||
|
|
@ -30,12 +30,12 @@ pub struct TournamentModeStartedEvent<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Event<'a> for 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 = skip(input, "\nBlue Team: ".len())?;
|
||||||
let (input, blue) = take_until(input, b'\n');
|
let (input, blue) = take_until(input, b'\n');
|
||||||
let input = skip(input, "\nRed Team: ".len())?;
|
let input = skip(input, "\nRed Team: ".len())?;
|
||||||
let (input, red) = take_until(input, b'\n');
|
let (_, red) = take_until(input, b'\n');
|
||||||
Ok((input, TournamentModeStartedEvent { blue, red }))
|
Ok(TournamentModeStartedEvent { blue, red })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -56,7 +56,7 @@ pub struct PointCapturedEvent<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Event<'a> for 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 = Default::default();
|
||||||
let mut cp_name = Default::default();
|
let mut cp_name = Default::default();
|
||||||
let mut num_cappers = Default::default();
|
let mut num_cappers = Default::default();
|
||||||
|
|
@ -94,15 +94,12 @@ impl<'a> Event<'a> for PointCapturedEvent<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok((
|
Ok(PointCapturedEvent {
|
||||||
input,
|
cp,
|
||||||
PointCapturedEvent {
|
num_cappers,
|
||||||
cp,
|
cp_name,
|
||||||
num_cappers,
|
players,
|
||||||
cp_name,
|
})
|
||||||
players,
|
|
||||||
},
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::event::{param_parse_with, parse_field, ParamIter};
|
use crate::event::{param_parse_with, parse_field, ParamIter};
|
||||||
use crate::raw_event::RawSubject;
|
use crate::raw_event::RawSubject;
|
||||||
use crate::{Event, IResult};
|
use crate::{Event, Result};
|
||||||
|
|
||||||
#[derive(Debug, Event)]
|
#[derive(Debug, Event)]
|
||||||
pub struct HealedEvent<'a> {
|
pub struct HealedEvent<'a> {
|
||||||
|
|
|
||||||
|
|
@ -29,22 +29,21 @@ trait GameEventErrTrait<T> {
|
||||||
fn with_raw(self, raw: &RawEvent) -> Result<T, GameEventError>;
|
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> {
|
fn with_raw(self, raw: &RawEvent) -> Result<T, GameEventError> {
|
||||||
self.map_err(|err| GameEventError::Error {
|
self.map_err(|err| GameEventError::Error {
|
||||||
err: Box::new(err),
|
err: Box::new(err),
|
||||||
ty: raw.ty,
|
ty: raw.ty,
|
||||||
params: raw.params.to_string(),
|
params: raw.params.to_string(),
|
||||||
})
|
})
|
||||||
.map(|(_rest, t)| t)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Event<'a>: Sized + 'a {
|
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)
|
T::parse(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -111,8 +110,8 @@ pub struct UnparsedEvent<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Event<'a> for UnparsedEvent<'a> {
|
impl<'a> Event<'a> for UnparsedEvent<'a> {
|
||||||
fn parse(input: &'a str) -> IResult<Self> {
|
fn parse(input: &'a str) -> Result<Self> {
|
||||||
Ok(("", UnparsedEvent { params: input }))
|
Ok(UnparsedEvent { params: input })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::common::{Class, Team};
|
use crate::common::{Class, Team};
|
||||||
use crate::event::{param_parse_with, parse_field, quoted, ParamIter};
|
use crate::event::{param_parse_with, parse_field, quoted, ParamIter};
|
||||||
use crate::raw_event::RawSubject;
|
use crate::raw_event::RawSubject;
|
||||||
use crate::{Error, Event, IResult};
|
use crate::{Error, Event, Result};
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::num::NonZeroU32;
|
use std::num::NonZeroU32;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue