Parser

Struct Parser 

Source
pub struct Parser<V: Version> { /* private fields */ }
Expand description

A configurable replay parser. Construct a new parser with default paramaters or use the ParserBuilder for fine grained control.

§Example

use faf_replay_parser::{Parser, SCFA};
use std::io::Read;

let mut data: &[u8] = b"Some replay data";

let parser = Parser::<SCFA>::new();
let result = parser.parse(&mut data)
    .expect_err("Sadly not a valid replay");

Implementations§

Source§

impl<V: Version> Parser<V>

Source

pub fn new() -> Parser<V>

Constructs a new parser with default settings. This will only parse the most essential commands needed to determine the number of participants, the length of the replay, and whether or not the replay desynced.

Source

pub fn with_options(options: ParserOptions<V>) -> Parser<V>

Constructs a new Parser with given ParserOptions

Source

pub fn new_stream(&self) -> StreamParser<V>

Creates a new StreamParser with the same options as self.

Source

pub fn parse( &self, reader: &mut (impl Read + BufRead), ) -> ReplayResult<Replay<V>>

Fully parses a stream of bytes into a Replay struct.

Source

pub fn parse_with_callback( &self, reader: &mut (impl Read + BufRead), callback: impl Fn(&mut SimData, &V::Command) -> ReplayResult<()>, ) -> ReplayResult<Replay<V>>

Like parse but using a custom command processing function. This can be useful for aggregating replay results on the fly without saving the whole command stream to a Vec first.

§Example
use faf_replay_parser::{ParserBuilder, SCFA};
use faf_replay_parser::scfa::ReplayCommand;

let mut data: &[u8] = b"Some replay data";

let parser = ParserBuilder::<SCFA>::new()
    .save_commands(false)
    .build();

let replay = parser.parse_with_callback(&mut data, |sim, command| {
    if let ReplayCommand::Advance { ticks } = command {
        println!("Advancing {}!", ticks);
    }
    Ok(())
});
Source

pub fn parse_header( &self, reader: &mut (impl Read + BufRead), ) -> ReplayResult<ReplayHeader>

Parses a stream of bytes into a ReplayHeader struct.

Source

pub fn parse_body(&self, reader: &mut impl Read) -> ReplayResult<ReplayBody<V>>

Parses a stream of bytes into a ReplayBody struct. Usually this means the header has already been parsed so that reader starts at the correct offset for the replay body.

Source

pub fn parse_body_with_callback( &self, reader: &mut impl Read, callback: impl Fn(&mut SimData, &V::Command) -> ReplayResult<()>, ) -> ReplayResult<ReplayBody<V>>

Like parse_body but using a custom command processing function. See parse_with_callback for an example callback function.

Trait Implementations§

Source§

impl<V: Debug + Version> Debug for Parser<V>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<V> Freeze for Parser<V>

§

impl<V> RefUnwindSafe for Parser<V>

§

impl<V> Send for Parser<V>
where <V as Version>::CommandId: Send,

§

impl<V> Sync for Parser<V>
where <V as Version>::CommandId: Sync,

§

impl<V> Unpin for Parser<V>
where <V as Version>::CommandId: Unpin,

§

impl<V> UnwindSafe for Parser<V>
where <V as Version>::CommandId: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.