ParserBuilder

Struct ParserBuilder 

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

A builder for configuring replay Parsers. See build for an example.

Implementations§

Source§

impl<V: Version> ParserBuilder<V>

Source

pub fn new() -> ParserBuilder<V>

Initialize with default options

Source

pub fn build(self) -> Parser<V>

Creates a new Parser by moving the internal ParserOptions and consuming self.

§Example
use faf_replay_parser::scfa::{replay_command, ReplayCommandId};
use faf_replay_parser::{ParserBuilder, SCFA};
use std::convert::TryFrom;

let parser = ParserBuilder::<SCFA>::new()
    .commands(&[
        ReplayCommandId::try_from(replay_command::ADVANCE).unwrap(),
        ReplayCommandId::try_from(replay_command::VERIFY_CHECKSUM).unwrap(),
        ReplayCommandId::try_from(replay_command::END_GAME).unwrap(),
    ])
    .build();
Source

pub fn build_stream(self) -> StreamParser<V>

Like build but creates a new StreamParser.

Source

pub fn build_clone(&self) -> Parser<V>

Creates a new Parser by cloning the internal ParserOptions. Useful when constructing many parsers with similar options.

Example

use faf_replay_parser::scfa::{replay_command, ReplayCommandId};
use faf_replay_parser::{ParserBuilder, SCFA};
use std::convert::TryFrom;

let mut builder = ParserBuilder::<SCFA>::new().commands(&[
    ReplayCommandId::try_from(replay_command::ADVANCE).unwrap(),
    ReplayCommandId::try_from(replay_command::END_GAME).unwrap(),
]);

// Can only count game ticks
let tick_parser = builder.build_clone();

let builder =
    builder.command(ReplayCommandId::try_from(replay_command::VERIFY_CHECKSUM).unwrap());
// Can count game ticks and detect desyncs
let desync_parser = builder.build_clone();

let builder =
    builder.command(ReplayCommandId::try_from(replay_command::LUA_SIM_CALLBACK).unwrap());
// Can count game ticks, detect desyncs, and extract chat messages
let message_parser = builder.build();
Source

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

Like build_clone but creates a new StreamParser.

Source

pub fn command(self, command: V::CommandId) -> ParserBuilder<V>

Add a command to the ParserOptions.

Source

pub fn commands(self, commands: &[V::CommandId]) -> ParserBuilder<V>

Add multiple commands to the ParserOptions.

Source

pub fn commands_all(self) -> ParserBuilder<V>

Add all supported commands to the ParserOptions.

Source

pub fn commands_default(self) -> ParserBuilder<V>

Add the default set of commands to the ParserOptions.

Default commands are ADVANCE, SET_COMMAND_SOURCE, COMMAND_SOURCE_TERMINATED, VERIFY_CHECKSUM, and END_GAME

Source

pub fn limit(self, limit: Option<usize>) -> ParserBuilder<V>

Set a limit on the number of commands to parse. This only applies to commands in the ParserOptions.commands field.

Source

pub fn save_commands(self, save_commands: bool) -> ParserBuilder<V>

Whether or not to store the parsed commands in the parsed ReplayBody. When set to false, Replay.body.commands.len() will always be 0.

Source

pub fn stop_on_desync(self, stop_on_desync: bool) -> ParserBuilder<V>

Whether or not to return an error if a desync is detected. When set to false, Replay.sim.desync_ticks will be a list of all desynced ticks.

Trait Implementations§

Source§

impl<V: Debug + Version> Debug for ParserBuilder<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 ParserBuilder<V>

§

impl<V> RefUnwindSafe for ParserBuilder<V>

§

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

§

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

§

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

§

impl<V> UnwindSafe for ParserBuilder<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.