Skip to content

Commit 94c83bf

Browse files
authored
adds implementation of ElementStreamReader (#432)
* adds changes for `ElementStreamReader` * adds `Display` for `StreamItem` * adds more unit tests for the reader
1 parent 5693330 commit 94c83bf

File tree

4 files changed

+637
-1
lines changed

4 files changed

+637
-1
lines changed

src/reader.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use crate::types::decimal::Decimal;
1717
use crate::types::integer::Integer;
1818
use crate::types::timestamp::Timestamp;
1919
use crate::{IonType, RawBinaryReader, RawTextReader};
20+
use std::fmt::{Display, Formatter};
2021

2122
/// Configures and constructs new instances of [Reader].
2223
pub struct ReaderBuilder {}
@@ -145,6 +146,29 @@ pub enum StreamItem {
145146
Nothing,
146147
}
147148

149+
impl StreamItem {
150+
/// If `is_null` is `true`, returns `StreamItem::Value(ion_type)`. Otherwise,
151+
/// returns `StreamItem::Null(ion_type)`.
152+
pub fn nullable_value(ion_type: IonType, is_null: bool) -> StreamItem {
153+
if is_null {
154+
StreamItem::Null(ion_type)
155+
} else {
156+
StreamItem::Value(ion_type)
157+
}
158+
}
159+
}
160+
161+
impl Display for StreamItem {
162+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
163+
use StreamItem::*;
164+
match self {
165+
Value(ion_type) => write!(f, "{}", ion_type),
166+
Null(ion_type) => write!(f, "null.{}", ion_type),
167+
Nothing => Ok(()),
168+
}
169+
}
170+
}
171+
148172
impl<R: RawReader> UserReader<R> {
149173
pub fn read_raw_symbol(&mut self) -> IonResult<RawSymbolToken> {
150174
self.raw_reader.read_symbol()

src/text/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pub mod non_blocking;
2-
mod parent_container;
2+
pub(crate) mod parent_container;
33
pub(crate) mod parse_result;
44
pub(in crate::text) mod parsers;
55
pub mod raw_text_reader;

0 commit comments

Comments
 (0)