Skip to main content

BufParse

Struct BufParse 

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

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()
    }
}

Implementations§

Source§

impl<R: BufParseInput> BufParse<R>

Source

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

Create a new parser.

Source

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

Read the next chunk of input into the buffer.

Source

pub fn try_next( &mut self, ) -> Result<Option<Streaming<Paragraph<'_>>>, BufParseError<'_>>

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

pub fn into_inner(self) -> R

Consume this BufParse and return the wrapped input source.

Any input that was already buffered will be lost.

Trait Implementations§

Source§

impl<R: Debug> Debug for BufParse<R>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

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

§

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

§

impl<R> UnwindSafe for BufParse<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.