MoveByMoveDecoder

Struct MoveByMoveDecoder 

Source
pub struct MoveByMoveDecoder<'a> { /* private fields */ }
Expand description

Iterator to decode a game move by move, rather than all at once. This allows for more fine-grained processing than decode_game.

§Examples


let encoded = encode_pgn("1. e4 c5 2. Nf3 e6 3. c3 d5 4. exd5")?;
let mut capture_count = 0;
let mut decoder = MoveByMoveDecoder::new(&encoded);
for d in decoder.into_iter_moves_and_positions() {
    let (mv, _) = d?;
    if mv.is_capture() {
        capture_count += 1;
    }
}
assert_eq!(capture_count, 1);

Implementations§

Source§

impl<'a> MoveByMoveDecoder<'a>

Source

pub fn new(encoded: &'a EncodedGame) -> Self

Construct a new MoveByMoveDecoder from an EncodedGame.

Source§

impl MoveByMoveDecoder<'_>

Source

pub fn next_move(&mut self) -> Option<DecodeResult<Move>>

Returns the next move.

Source

pub fn next_position(&mut self) -> Option<DecodeResult<&Chess>>

Returns the resulting position when the next move is played.

Source

pub fn next_move_and_position(&mut self) -> Option<DecodeResult<(Move, &Chess)>>

Returns the next move and the resulting position when the move is played.

Source

pub fn into_iter_moves(self) -> impl Iterator<Item = DecodeResult<Move>>

Turns the decoder into an iterator over the moves in the chess game.

As soon as an error is encountered, all subsequent iterations yield the same error.

Source

pub fn into_iter_positions(self) -> impl Iterator<Item = DecodeResult<Chess>>

Turns the decoder into an iterator over the positions in the chess game. The first yielded position is the position after the first move.

As soon as an error is encountered, all subsequent iterations yield the same error.

Source

pub fn into_iter_moves_and_positions( self, ) -> impl Iterator<Item = DecodeResult<(Move, Chess)>>

Turns the decoder into an iterator over the moves and positions in the chess game. The yielded position is the position after the move.

As soon as an error is encountered, all subsequent iterations yield the same error.

Auto Trait Implementations§

§

impl<'a> Freeze for MoveByMoveDecoder<'a>

§

impl<'a> RefUnwindSafe for MoveByMoveDecoder<'a>

§

impl<'a> Send for MoveByMoveDecoder<'a>

§

impl<'a> Sync for MoveByMoveDecoder<'a>

§

impl<'a> Unpin for MoveByMoveDecoder<'a>

§

impl<'a> UnwindSafe for MoveByMoveDecoder<'a>

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.