Skip to content

Commit

Permalink
adds implementation of ElementStreamReader (#432)
Browse files Browse the repository at this point in the history
* adds changes for `ElementStreamReader`
* adds `Display` for `StreamItem`
* adds more unit tests for the reader
  • Loading branch information
desaikd committed Oct 7, 2022
1 parent 5693330 commit 94c83bf
Show file tree
Hide file tree
Showing 4 changed files with 637 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::types::decimal::Decimal;
use crate::types::integer::Integer;
use crate::types::timestamp::Timestamp;
use crate::{IonType, RawBinaryReader, RawTextReader};
use std::fmt::{Display, Formatter};

/// Configures and constructs new instances of [Reader].
pub struct ReaderBuilder {}
Expand Down Expand Up @@ -145,6 +146,29 @@ pub enum StreamItem {
Nothing,
}

impl StreamItem {
/// If `is_null` is `true`, returns `StreamItem::Value(ion_type)`. Otherwise,
/// returns `StreamItem::Null(ion_type)`.
pub fn nullable_value(ion_type: IonType, is_null: bool) -> StreamItem {
if is_null {
StreamItem::Null(ion_type)
} else {
StreamItem::Value(ion_type)
}
}
}

impl Display for StreamItem {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
use StreamItem::*;
match self {
Value(ion_type) => write!(f, "{}", ion_type),
Null(ion_type) => write!(f, "null.{}", ion_type),
Nothing => Ok(()),
}
}
}

impl<R: RawReader> UserReader<R> {
pub fn read_raw_symbol(&mut self) -> IonResult<RawSymbolToken> {
self.raw_reader.read_symbol()
Expand Down
2 changes: 1 addition & 1 deletion src/text/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod non_blocking;
mod parent_container;
pub(crate) mod parent_container;
pub(crate) mod parse_result;
pub(in crate::text) mod parsers;
pub mod raw_text_reader;
Expand Down
Loading

0 comments on commit 94c83bf

Please sign in to comment.