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>
impl<R: BufParseInput> BufParse<R>
Sourcepub fn try_next(
&mut self,
) -> Result<Option<Streaming<Paragraph<'_>>>, BufParseError<'_>>
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 returnNone. - If it’s
Streaming::Incomplete, there’s not enough buffered input to make a parsing decision. Callbufferto read more input. - If it’s
Streaming::Item, a paragraph was parsed. Calltry_nextagain after processing it.
Sourcepub fn into_inner(self) -> R
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more