-
Notifications
You must be signed in to change notification settings - Fork 32
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
Implements IntoIterator
for container Elements
#499
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
} | ||
} | ||
|
||
/// An in-memory representation of an Ion Struct |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add macro examples here as well?
|
||
#[test] | ||
fn for_field_in_struct() { | ||
// Simple example to exercise List's implementation of IntoIterator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Simple example to exercise List's implementation of IntoIterator | |
// Simple example to exercise Struct's implementation of IntoIterator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗺️ PR tour
// Allows `for element in &list {...}` syntax | ||
impl<'a> IntoIterator for &'a List { | ||
type Item = &'a Element; | ||
type IntoIter = ElementsIterator<'a>; | ||
|
||
fn into_iter(self) -> Self::IntoIter { | ||
self.elements() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗺️ This impl (and its unit test) is the only new code in this file; the rest was moved here from mod.rs
.
use std::fmt::{Display, Formatter}; | ||
|
||
pub mod builders; | ||
mod element_stream_reader; | ||
mod iterators; | ||
pub mod owned; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗺️ The owned
module was emptied out in a prior PR but I forgot to remove it.
pub mod reader; | ||
mod sequence; | ||
mod sexp; | ||
mod r#struct; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗺️ struct
is a Rust keyword and so needs to be escaped when used as a module name. The module itself is not public, however, so this clunkiness is not exposed to users. The Struct
type is re-exported from mod.rs
.
pub mod writer; | ||
|
||
/// Behavior that is common to both [SExp] and [Struct]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗺️ The IonSequence
trait was moved to the new sequence
module.
|
||
/// An in-memory representation of an Ion list | ||
#[derive(Debug, Clone, PartialEq, Eq)] | ||
pub struct List { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗺️ The List
type was moved to the new list
module.
@@ -358,20 +53,6 @@ impl IonEq for Value { | |||
} | |||
} | |||
|
|||
impl IonEq for Vec<Element> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗺️ This impl was moved to the new sequence
module.
src/element/owned.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗺️ This module was emptied out in #491 but I forgot to delete the file.
src/element/sequence.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗺️ All of this was moved here from mod
.
// Allows `for element in &sexp {...}` syntax | ||
impl<'a> IntoIterator for &'a SExp { | ||
type Item = &'a Element; | ||
type IntoIter = ElementsIterator<'a>; | ||
|
||
fn into_iter(self) -> Self::IntoIter { | ||
self.elements() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗺️ This impl (and its unit test) is the only new code in this module. Everything else was moved here from mod
.
// Allows `for (name, value) in &my_struct {...}` syntax | ||
impl<'a> IntoIterator for &'a Struct { | ||
type Item = (&'a Symbol, &'a Element); | ||
type IntoIter = FieldIterator<'a>; | ||
|
||
fn into_iter(self) -> Self::IntoIter { | ||
self.iter() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗺️ This impl (and its unit test) is the only new code in this module. Everything else was moved here from mod
.
This PR adds implementations of
IntoIterator
for each of the containerElement
types, allowing the expected looping syntax:It also moves the container types to their own modules for easier navigation.
Each commit is self-contained. Only the final commit (
Implements IntoIterator...
) contains any new logic. The rest are mechanical refactorings. I recommend reviewing them in order.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.