[][src]Struct debcontrol::BufParse

pub struct BufParse<R> { /* fields omitted */ }

A streaming control file parser that buffers input internally.

This type handles incrementally reading and buffering input from a source implementing the BufParseInput trait.

Example

use debcontrol::{BufParse, Streaming};
use std::fs::File;

let f = File::open(file_name).unwrap();
let mut buf_parse = BufParse::new(f, 4096);
while let Some(result) = buf_parse.try_next().unwrap() {
    match result {
        Streaming::Item(paragraph) => {
            for field in paragraph.fields {
                println!("{}: {}", field.name, &field.value);
            }
        }
        Streaming::Incomplete => buf_parse.buffer().unwrap()
    }
}

Methods

impl<R: BufParseInput> BufParse<R>[src]

pub fn new(read: R, chunk_size: usize) -> Self[src]

Create a new parser.

pub fn buffer(&mut self) -> Result<(), R::Error>[src]

Read the next chunk of input into the buffer.

pub fn try_next(
    &mut self
) -> Result<Option<Streaming<Paragraph>>, BufParseError>
[src]

Try to parse the next paragraph from the input.

A syntax error encountered during parsing is returned immediately. Otherwise, the nature of the Ok result determines what to do next:

  • If it's None, all input has been parsed. Future calls will continue to return None.
  • If it's Streaming::Incomplete, there's not enough buffered input to make a parsing decision. Call buffer to read more input.
  • If it's Streaming::Item, a paragraph was parsed. Call try_next again after processing it.

pub fn into_inner(self) -> R[src]

Consume this BufParse and return the wrapped input source.

Any input that was already buffered will be lost.

Trait Implementations

impl<R: Debug> Debug for BufParse<R>[src]

Auto Trait Implementations

impl<R> RefUnwindSafe for BufParse<R> where
    R: RefUnwindSafe

impl<R> Send for BufParse<R> where
    R: Send

impl<R> Sync for BufParse<R> where
    R: Sync

impl<R> Unpin for BufParse<R> where
    R: Unpin

impl<R> UnwindSafe for BufParse<R> where
    R: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.