Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial implementation of the Ion 1.1 text reader #645

Merged
merged 4 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ num-integer = "0.1.44"
num-traits = "0.2"
arrayvec = "0.7"
smallvec = {version ="1.9.0", features = ["const_generics"]}
bumpalo = {version = "3.13.0", features = ["collections"]}
digest = { version = "0.9", optional = true }
sha2 = { version = "0.9", optional = true }
serde = { version = "1.0", features = ["derive"], optional = true }
Expand Down
2 changes: 1 addition & 1 deletion examples/lazy_read_all_values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ mod lazy_reader_example {
fn count_struct_children(lazy_struct: &LazyBinaryStruct) -> IonResult<usize> {
let mut count = 0;
for field in lazy_struct {
count += count_value_and_children(field?.value())?;
count += count_value_and_children(&field?.value())?;
}
Ok(count)
}
Expand Down
8 changes: 7 additions & 1 deletion src/element/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,18 @@ impl IonOrd for Element {
}

/// An `(annotations, value)` pair representing an Ion value.
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct Element {
annotations: Annotations,
value: Value,
}

impl std::fmt::Debug for Element {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
<Element as Display>::fmt(self, f)
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗺️ The default Debug implementation for Element is so verbose that your eyes glaze over just trying to see that this contains an int. It's used transitively by some other types' Debug implementations too. I've switched it over to forwarding the call to its Display impl, yielding text Ion. It's usually much more helpful.


impl Element {
pub(crate) fn new(annotations: Annotations, value: impl Into<Value>) -> Self {
Self {
Expand Down
2 changes: 1 addition & 1 deletion src/element/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub trait ElementReader {
/// returning the complete sequence as a `Vec<Element>`.
///
/// If an error occurs while reading, returns `Err(IonError)`.
fn read_all_elements(&mut self) -> IonResult<Vec<Element>> {
fn read_all_elements(&mut self) -> IonResult<Sequence> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗺️ A previous PR changed Element::read_all to return a Sequence (which is just an opaque wrapper around Vec<Element>. However, we neglected to make the same change to the read_all_elements method in the ElementReader trait. I've made that change here for interop/consistency.

self.elements().collect()
}
}
Expand Down
Loading