41 lines
1.0 KiB
Rust
41 lines
1.0 KiB
Rust
use super::reader::{Reader, is_eof_error};
|
|
use super::value::IOValue;
|
|
|
|
pub use super::reader::{Result, DecodePlaceholderMap};
|
|
|
|
pub struct Decoder<'a, R: Reader> {
|
|
pub read: R,
|
|
placeholders: Option<&'a DecodePlaceholderMap>,
|
|
read_annotations: bool,
|
|
}
|
|
|
|
impl<'a, R: Reader> Decoder<'a, R> {
|
|
pub fn new(read: R, placeholders: Option<&'a DecodePlaceholderMap>) ->
|
|
Self
|
|
{
|
|
Decoder {
|
|
read,
|
|
placeholders,
|
|
read_annotations: true,
|
|
}
|
|
}
|
|
|
|
pub fn set_read_annotations(&mut self, read_annotations: bool) {
|
|
self.read_annotations = read_annotations
|
|
}
|
|
|
|
pub fn next_or_err(&mut self) -> Result<IOValue> {
|
|
self.read.next(self.placeholders, self.read_annotations)
|
|
}
|
|
}
|
|
|
|
impl<'a, R: Reader> std::iter::Iterator for Decoder<'a, R> {
|
|
type Item = Result<IOValue>;
|
|
fn next(&mut self) -> Option<Self::Item> {
|
|
match self.next_or_err() {
|
|
Err(e) if is_eof_error(&e) => None,
|
|
other => Some(other)
|
|
}
|
|
}
|
|
}
|