pub trait CommandIter<'a> {
type Iter: Iterator<Item = ReplayCommandFrameSpan<'a>>;
// Required method
fn iter_command_frames_raw(&self) -> Self::Iter;
// Provided methods
fn iter_command_frames<V: Version>(&self) -> VerifyFrame<'a, V, Self::Iter> ⓘ { ... }
fn iter_commands<V: Version>(&self) -> ParseCommand<'a, V, Self::Iter> ⓘ { ... }
}Expand description
Allow objects to return iterators over contained command frames.
Required Associated Types§
type Iter: Iterator<Item = ReplayCommandFrameSpan<'a>>
Required Methods§
Sourcefn iter_command_frames_raw(&self) -> Self::Iter
fn iter_command_frames_raw(&self) -> Self::Iter
Return an iterator over the raw command frame data. The iterator should not validate the contents of the command identifier or the command data. It is up to the implementor to decide how to handle frames with sizes less than the frame size.
§Examples
use faf_replay_parser::iter::prelude::*;
use faf_replay_parser::iter::{parse_command, verify_frame_header};
use faf_replay_parser::SCFA;
use faf_replay_parser::scfa::ReplayCommand::*;
let data: &[u8] = &[
1, 4, 0, 1, // SetCommandSource
0, 7, 0, 1, 0, 0, 0, // Advance
5, 3, 0 // RequestPause
];
let mut iter = data.iter_command_frames_raw()
.filter(|frame| frame.cmd < 3)
.filter_map(|frame| verify_frame_header::<SCFA>(frame).ok())
.filter_map(|frame| parse_command::<SCFA>(frame).ok());
match iter.next() {
Some(SetCommandSource { id: 1 }) => {},
e => panic!("wrong result {:?}", e)
}
match iter.next() {
Some(Advance { ticks: 1 }) => {},
e => panic!("wrong result {:?}", e)
}
assert!(iter.next().is_none());
Provided Methods§
Sourcefn iter_command_frames<V: Version>(&self) -> VerifyFrame<'a, V, Self::Iter> ⓘ
fn iter_command_frames<V: Version>(&self) -> VerifyFrame<'a, V, Self::Iter> ⓘ
Return an iterator over the command frames. The command frame header will be checked for validity, and any errors returned.
Note: If only a subset of commands are needed, it can be more efficient to compose
iter_command_frames_raw with a filter and map adapter to call verify_frame_header
only for frames that have the desired command id.
Sourcefn iter_commands<V: Version>(&self) -> ParseCommand<'a, V, Self::Iter> ⓘ
fn iter_commands<V: Version>(&self) -> ParseCommand<'a, V, Self::Iter> ⓘ
Return an iterator over the parsed Commands, verifying the command headers and
returning any errors.
§Examples
use faf_replay_parser::iter::prelude::*;
use faf_replay_parser::SCFA;
use faf_replay_parser::{ReplayResult, scfa::ReplayCommand};
let data: &[u8] = &[0, 7, 0, 1, 0, 0, 0, 1, 0, 0, 23, 3, 0];
let commands = data.iter_commands::<SCFA>()
.collect::<Vec<ReplayResult<ReplayCommand>>>();
assert_eq!(
format!("{:?}", commands),
"[Ok(Advance { ticks: 1 }), Err(Malformed(\"invalid command size\")), Ok(EndGame)]"
)Note: If only a subset of commands are needed, it can be more efficient to compose
iter_command_frames with a filter and map adapter to call parse_command
only for frames that have the desired command id.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.