[][src]Struct fafreplay::scfa::Parser

pub struct Parser { /* fields omitted */ }

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

Example

use fafreplay::scfa::*;
use std::io::Read;

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

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

Methods

impl Parser[src]

pub fn new() -> Parser[src]

Construct 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.

pub fn parse<'a>(&self, data: &'a mut impl Read) -> ReplayResult<Replay>[src]

Fully parse a stream of bytes into a Replay struct.

pub fn parse_with_callback<'a>(
    &self,
    data: &'a mut impl Read,
    callback: impl Fn(&mut SimData, &ReplayCommand) -> ReplayResult<()>
) -> ReplayResult<Replay>
[src]

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 fafreplay::scfa::*;

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

let parser = ParserBuilder::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(())
});

pub fn parse_header<'a>(
    &self,
    data: &'a mut impl Read
) -> ReplayResult<ReplayHeader>
[src]

Only parse a stream of bytes into a ReplayHeader struct.

pub fn parse_body<'a>(
    &self,
    data: &'a mut impl Read
) -> ReplayResult<ReplayBody>
[src]

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

pub fn parse_body_with_callback<'a>(
    &self,
    data: &'a mut impl Read,
    callback: impl Fn(&mut SimData, &ReplayCommand) -> ReplayResult<()>
) -> ReplayResult<ReplayBody>
[src]

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

Auto Trait Implementations

impl Send for Parser

impl Unpin for Parser

impl Sync for Parser

impl UnwindSafe for Parser

impl RefUnwindSafe for Parser

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]