Reader

Struct Reader 

Source
pub struct Reader<R> { /* private fields */ }
Expand description

Reads a PGN and calls Visitor methods.

Buffers the underlying reader with an appropriate strategy, so it’s not recommended to add an additional layer of buffering like BufReader.

Implementations§

Source§

impl<R: Read> Reader<R>

Source

pub fn new(reader: R) -> Reader<R>

Create a reader with default settings based on the PGN standard.

Source

pub fn build(reader: R) -> ReaderBuilder<R>

Build a reader with custom settings.

use std::fs::File;
use pgn_reader::Reader;

let reader = Reader::build(File::open("example.pgn")?)
    .set_supported_tag_line_length(1000)
    .set_supported_comment_length(4000)
    .finish();
Source

pub fn read_game<V: Visitor>( &mut self, visitor: &mut V, ) -> Result<Option<V::Output>>

Read a single game, if any, and return the result produced by the visitor.

Returns Ok(None) if the underlying reader is empty.

§Errors
  • I/O error from the underlying reader.
  • Irrecoverable parser errors.
Source

pub fn has_more(&mut self) -> Result<bool>

Returns whether the reader has another game to parse, but does not actually parse it.

§Errors
  • I/O error from the underlying reader.
  • Irrecoverable parser errors (while trying to read previous unfinished game to completion).
Source

pub fn skip_game(&mut self) -> Result<bool>

Skip a single game, if any.

Returns Ok(true) if a game found and skipped.

§Errors
  • I/O error from the underlying reader.
  • Irrecoverable parser errors.
Source

pub fn read_games<'a, V: Visitor>( &'a mut self, visitor: &'a mut V, ) -> ReadGames<'a, R, V>

Iterate over all games, yielding the visitor outputs.

Source

pub fn visit_all_games<V: Visitor>(&mut self, visitor: &mut V) -> Result<()>

Visit all games, ignoring the visitor outputs.

§Errors
  • I/O error from the underlying reader.
  • Irrecoverable parser errors.
Source

pub fn buffer(&self) -> &[u8]

The currently buffered bytes.

Source

pub fn into_inner(self) -> R

Discard the remaining bytes in the buffer (Reader::buffer()) and get the underlying reader.

Trait Implementations§

Source§

impl<R: Clone> Clone for Reader<R>

Source§

fn clone(&self) -> Reader<R>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<R: Debug> Debug for Reader<R>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<R: Seek> Seek for Reader<R>

Source§

fn seek(&mut self, pos: SeekFrom) -> Result<u64>

Seek to an offset, in bytes, in a stream. Read more
Source§

fn seek_relative(&mut self, offset: i64) -> Result<()>

Seeks relative to the current position. Read more
Source§

fn stream_position(&mut self) -> Result<u64>

Returns the current seek position from the start of the stream. Read more
1.55.0 · Source§

fn rewind(&mut self) -> Result<(), Error>

Rewind to the beginning of a stream. Read more
Source§

fn stream_len(&mut self) -> Result<u64, Error>

🔬This is a nightly-only experimental API. (seek_stream_len)
Returns the length of this stream (in bytes). Read more

Auto Trait Implementations§

§

impl<R> Freeze for Reader<R>
where R: Freeze,

§

impl<R> RefUnwindSafe for Reader<R>
where R: RefUnwindSafe,

§

impl<R> Send for Reader<R>
where R: Send,

§

impl<R> Sync for Reader<R>
where R: Sync,

§

impl<R> Unpin for Reader<R>
where R: Unpin,

§

impl<R> UnwindSafe for Reader<R>
where R: 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.