Skip to main content

Reader

Struct Reader 

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

A streaming, event-based SIF reader.

Reads lines from any BufRead source and yields Event values one at a time via next_event().

use sif_parser::{Reader, Event};
let mut reader = Reader::from_str(sif_text);
while let Some(event) = reader.next_event()? {
    match event {
        Event::Record(r) => { /* process record */ }
        _ => {}
    }
}

Implementations§

Source§

impl<R: BufRead> Reader<R>

Source

pub fn new(source: R) -> Self

Create a new reader from a buffered source.

Source

pub fn schema(&self) -> Option<&Schema>

Returns the current active schema, if any.

Source

pub fn line_num(&self) -> usize

Returns the current line number (1-based).

Source

pub fn next_event(&mut self) -> Result<Option<Event>>

Read the next event from the stream.

Returns Ok(None) at end of input.

Source

pub fn collect_events(&mut self) -> Result<Vec<Event>>

Collect all events into a Vec (convenience for testing/small docs).

Source§

impl Reader<BufReader<Cursor<String>>>

Create a reader from a string.

Source

pub fn from_str(input: &str) -> Self

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> UnsafeUnpin for Reader<R>
where R: UnsafeUnpin,

§

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