From 2ac40f71c365414fcc4d8337e6765dde81816858 Mon Sep 17 00:00:00 2001 From: Matthew Pope Date: Fri, 28 Apr 2023 10:47:40 -0700 Subject: [PATCH 1/3] Move the Ion value types to the types module --- src/binary/binary_writer.rs | 6 ++-- src/binary/decimal.rs | 6 +--- src/binary/int.rs | 10 +++--- src/binary/non_blocking/binary_buffer.rs | 4 +-- src/binary/non_blocking/raw_binary_reader.rs | 10 +++--- src/binary/raw_binary_writer.rs | 8 ++--- src/binary/timestamp.rs | 5 +-- src/binary/uint.rs | 2 +- src/blocking_reader.rs | 2 +- src/element/annotations.rs | 2 +- src/element/builders.rs | 4 +-- src/element/element_stream_reader.rs | 6 ++-- src/element/mod.rs | 23 +++++-------- src/element/reader.rs | 4 +-- src/ion_hash/representation.rs | 6 ++-- src/lib.rs | 11 +++---- src/raw_reader.rs | 2 +- src/reader.rs | 10 +++--- src/stream_reader.rs | 10 +++--- src/symbol_table.rs | 2 +- src/system_reader.rs | 10 +++--- src/text/non_blocking/raw_text_reader.rs | 12 +++---- src/text/parsers/containers.rs | 4 +-- src/text/parsers/decimal.rs | 8 ++--- src/text/parsers/integer.rs | 2 +- src/text/parsers/timestamp.rs | 8 ++--- src/text/parsers/top_level.rs | 2 +- src/text/raw_text_writer.rs | 6 ++-- src/text/text_value.rs | 6 ++-- src/text/text_writer.rs | 4 +-- src/{element => types}/bytes.rs | 0 src/types/coefficient.rs | 6 ++-- src/types/decimal.rs | 8 ++--- src/types/integer.rs | 8 ++--- src/{element => types}/iterators.rs | 6 ++-- src/{element => types}/list.rs | 4 +-- src/{element => types}/lob.rs | 0 src/types/mod.rs | 34 +++++++++++++++++--- src/{element => types}/sequence.rs | 2 +- src/{element => types}/sexp.rs | 4 +-- src/{element => types}/struct.rs | 2 +- src/{ => types}/symbol.rs | 0 src/types/timestamp.rs | 10 +++--- src/writer.rs | 6 ++-- tests/ion_hash_tests.rs | 2 +- tests/reexport_external.rs | 2 +- 46 files changed, 149 insertions(+), 140 deletions(-) rename src/{element => types}/bytes.rs (100%) rename src/{element => types}/iterators.rs (96%) rename src/{element => types}/list.rs (96%) rename src/{element => types}/lob.rs (100%) rename src/{element => types}/sequence.rs (97%) rename src/{element => types}/sexp.rs (96%) rename src/{element => types}/struct.rs (99%) rename src/{ => types}/symbol.rs (100%) diff --git a/src/binary/binary_writer.rs b/src/binary/binary_writer.rs index 164d4b52..cb20b8cc 100644 --- a/src/binary/binary_writer.rs +++ b/src/binary/binary_writer.rs @@ -2,11 +2,11 @@ use crate::binary::raw_binary_writer::{RawBinaryWriter, RawBinaryWriterBuilder}; use crate::constants::v1_0::system_symbol_ids; use crate::raw_symbol_token_ref::{AsRawSymbolTokenRef, RawSymbolTokenRef}; use crate::result::{illegal_operation, IonResult}; -use crate::types::decimal::Decimal; -use crate::types::timestamp::Timestamp; +use crate::types::Decimal; use crate::types::SymbolId; +use crate::types::Timestamp; use crate::writer::IonWriter; -use crate::{Int, IonType, SymbolTable}; +use crate::{types::Int, types::IonType, SymbolTable}; use delegate::delegate; use std::io::Write; diff --git a/src/binary/decimal.rs b/src/binary/decimal.rs index e33e9933..30b4aaba 100644 --- a/src/binary/decimal.rs +++ b/src/binary/decimal.rs @@ -11,11 +11,7 @@ use crate::{ int::DecodedInt, raw_binary_writer::MAX_INLINE_LENGTH, var_int::VarInt, var_uint::VarUInt, }, result::IonResult, - types::{ - coefficient::{Coefficient, Sign}, - decimal::Decimal, - integer::UInt, - }, + types::{Coefficient, Decimal, Sign, UInt}, IonError, }; diff --git a/src/binary/int.rs b/src/binary/int.rs index 6d40ef7c..b8768533 100644 --- a/src/binary/int.rs +++ b/src/binary/int.rs @@ -2,9 +2,9 @@ use std::mem; use crate::data_source::IonDataSource; use crate::result::{decoding_error, IonResult}; -use crate::types::coefficient; -use crate::types::coefficient::Coefficient; -use crate::Int; +use crate::types; +use crate::types::Coefficient; +use crate::types::Int; use num_bigint::{BigInt, Sign}; use num_traits::Zero; use std::io::Write; @@ -196,7 +196,7 @@ impl From for Coefficient { is_negative, .. // ignore `size_in_bytes` } = int; - use coefficient::Sign::{Negative, Positive}; + use types::Sign::{Negative, Positive}; let sign = if is_negative { Negative } else { Positive }; Coefficient::new(sign, value) } @@ -206,7 +206,7 @@ impl From for Coefficient { mod tests { use super::*; use crate::result::IonResult; - use crate::Int; + use crate::types::Int; use std::io; use std::io::Cursor; diff --git a/src/binary/non_blocking/binary_buffer.rs b/src/binary/non_blocking/binary_buffer.rs index b21d932b..d1044b7a 100644 --- a/src/binary/non_blocking/binary_buffer.rs +++ b/src/binary/non_blocking/binary_buffer.rs @@ -7,8 +7,8 @@ use crate::binary::uint::DecodedUInt; use crate::binary::var_int::VarInt; use crate::binary::var_uint::VarUInt; use crate::result::{decoding_error, incomplete_data_error, incomplete_data_error_raw}; -use crate::types::integer::UInt; -use crate::{Int, IonResult, IonType}; +use crate::types::UInt; +use crate::{types::Int, IonResult, IonType}; use num_bigint::{BigInt, BigUint, Sign}; use std::io::Read; use std::mem; diff --git a/src/binary/non_blocking/raw_binary_reader.rs b/src/binary/non_blocking/raw_binary_reader.rs index 66d4448a..351947d4 100644 --- a/src/binary/non_blocking/raw_binary_reader.rs +++ b/src/binary/non_blocking/raw_binary_reader.rs @@ -5,17 +5,17 @@ use crate::binary::non_blocking::type_descriptor::{Header, TypeDescriptor}; use crate::binary::uint::DecodedUInt; use crate::binary::var_uint::VarUInt; use crate::binary::IonTypeCode; -use crate::element::{Blob, Clob}; use crate::result::{ decoding_error, decoding_error_raw, illegal_operation, illegal_operation_raw, incomplete_data_error, }; -use crate::types::integer::IntAccess; -use crate::types::string::Str; +use crate::types::IntAccess; +use crate::types::Str; use crate::types::SymbolId; +use crate::types::{Blob, Clob}; use crate::{ - raw_reader::BufferedRawReader, Decimal, Int, IonReader, IonResult, IonType, RawStreamItem, - RawSymbolToken, Timestamp, + raw_reader::BufferedRawReader, types::Decimal, Int, IonReader, IonResult, IonType, + RawStreamItem, RawSymbolToken, Timestamp, }; use bytes::{BigEndian, Buf, ByteOrder}; use num_bigint::BigUint; diff --git a/src/binary/raw_binary_writer.rs b/src/binary/raw_binary_writer.rs index 98049952..238d6afb 100644 --- a/src/binary/raw_binary_writer.rs +++ b/src/binary/raw_binary_writer.rs @@ -11,8 +11,8 @@ use crate::binary::uint::DecodedUInt; use crate::binary::var_uint::VarUInt; use crate::raw_symbol_token_ref::{AsRawSymbolTokenRef, RawSymbolTokenRef}; use crate::result::{illegal_operation, IonResult}; -use crate::types::decimal::Decimal; -use crate::types::timestamp::Timestamp; +use crate::types::Decimal; +use crate::types::Timestamp; use crate::types::{ContainerType, SymbolId}; use crate::writer::IonWriter; use crate::{Int, IonType}; @@ -910,10 +910,10 @@ mod writer_tests { use rstest::*; use super::*; - use crate::element::{Blob, Clob}; use crate::raw_symbol_token::{local_sid_token, RawSymbolToken}; use crate::reader::{Reader, ReaderBuilder}; - use crate::symbol::Symbol; + use crate::types::Symbol; + use crate::types::{Blob, Clob}; use crate::IonReader; use num_bigint::BigInt; use num_traits::Float; diff --git a/src/binary/timestamp.rs b/src/binary/timestamp.rs index cdfc7ab2..232d617f 100644 --- a/src/binary/timestamp.rs +++ b/src/binary/timestamp.rs @@ -11,10 +11,7 @@ use crate::{ var_uint::VarUInt, }, result::IonResult, - types::{ - decimal::Decimal, - timestamp::{Mantissa, Precision, Timestamp}, - }, + types::{Decimal, Mantissa, Precision, Timestamp}, }; const MAX_TIMESTAMP_LENGTH: usize = 32; diff --git a/src/binary/uint.rs b/src/binary/uint.rs index ca67e256..e2c5ffee 100644 --- a/src/binary/uint.rs +++ b/src/binary/uint.rs @@ -4,7 +4,7 @@ use std::mem; use crate::data_source::IonDataSource; use crate::result::{decoding_error, IonResult}; -use crate::types::integer::{Int, UInt}; +use crate::types::{Int, UInt}; // This limit is used for stack-allocating buffer space to encode/decode UInts. const UINT_STACK_BUFFER_SIZE: usize = 16; diff --git a/src/blocking_reader.rs b/src/blocking_reader.rs index 15f9fc1a..a80bc10d 100644 --- a/src/blocking_reader.rs +++ b/src/blocking_reader.rs @@ -8,7 +8,7 @@ use crate::raw_reader::BufferedRawReader; use crate::result::IonResult; use crate::stream_reader::IonReader; use crate::text::non_blocking::raw_text_reader::RawTextReader; -use crate::types::timestamp::Timestamp; +use crate::types::Timestamp; use crate::{Decimal, Int, IonError, IonType, Str}; pub type BlockingRawTextReader = BlockingRawReader>, T>; diff --git a/src/element/annotations.rs b/src/element/annotations.rs index 58ebb376..f584a012 100644 --- a/src/element/annotations.rs +++ b/src/element/annotations.rs @@ -1,5 +1,5 @@ -use crate::element::iterators::{AnnotationsIntoIter, SymbolsIterator}; use crate::ion_data::IonOrd; +use crate::types::iterators::{AnnotationsIntoIter, SymbolsIterator}; use crate::Symbol; use std::cmp::Ordering; diff --git a/src/element/builders.rs b/src/element/builders.rs index 2bae0394..cc375d73 100644 --- a/src/element/builders.rs +++ b/src/element/builders.rs @@ -348,8 +348,8 @@ macro_rules! ion_struct { }}; } -use crate::element::list::List; -use crate::element::sexp::SExp; +use crate::types::List; +use crate::types::SExp; pub use ion_list; pub use ion_sexp; pub use ion_struct; diff --git a/src/element/element_stream_reader.rs b/src/element/element_stream_reader.rs index 31fc38d7..497db4b2 100644 --- a/src/element/element_stream_reader.rs +++ b/src/element/element_stream_reader.rs @@ -1,8 +1,8 @@ use crate::result::{decoding_error, illegal_operation, illegal_operation_raw}; use crate::text::parent_container::ParentContainer; -use crate::element::iterators::SymbolsIterator; use crate::element::{Blob, Clob, Element}; +use crate::types::iterators::SymbolsIterator; use crate::{ Decimal, Int, IonError, IonReader, IonResult, IonType, Str, StreamItem, Symbol, Timestamp, }; @@ -361,8 +361,8 @@ mod reader_tests { use super::*; use crate::result::IonResult; use crate::stream_reader::IonReader; - use crate::types::decimal::Decimal; - use crate::types::timestamp::Timestamp; + use crate::types::Decimal; + use crate::types::Timestamp; use crate::IonType; diff --git a/src/element/mod.rs b/src/element/mod.rs index 004112ca..a5d3ebf8 100644 --- a/src/element/mod.rs +++ b/src/element/mod.rs @@ -25,26 +25,19 @@ use std::fmt::{Display, Formatter}; mod annotations; pub mod builders; -mod bytes; mod element_stream_reader; -mod iterators; -mod list; -mod lob; pub mod reader; -mod sequence; -mod sexp; -mod r#struct; pub mod writer; // Re-export the Value variant types and traits so they can be accessed directly from this module. -pub use self::bytes::Bytes; +pub use crate::types::Bytes; +pub use crate::types::{Blob, Clob}; pub use annotations::{Annotations, IntoAnnotations}; -pub use lob::{Blob, Clob}; -pub use list::List; -pub use r#struct::Struct; -pub use sequence::Sequence; -pub use sexp::SExp; +pub use crate::types::List; +pub use crate::types::SExp; +pub use crate::types::Sequence; +pub use crate::types::Struct; impl IonEq for Value { fn ion_eq(&self, other: &Self) -> bool { @@ -614,7 +607,7 @@ where #[cfg(test)] mod tests { use crate::element::annotations::IntoAnnotations; - use crate::types::timestamp::Timestamp; + use crate::types::Timestamp; use crate::{ion_list, ion_sexp, ion_struct, Decimal, Int, IonType, Symbol}; use chrono::*; use rstest::*; @@ -864,7 +857,7 @@ mod tests { } use crate::element::{Annotations, Element, IntoAnnotatedElement, Struct}; - use crate::types::integer::IntAccess; + use crate::types::IntAccess; use num_bigint::BigInt; use std::collections::HashSet; use std::str::FromStr; diff --git a/src/element/reader.rs b/src/element/reader.rs index a9c9cfdf..c9ae0086 100644 --- a/src/element/reader.rs +++ b/src/element/reader.rs @@ -197,8 +197,8 @@ mod reader_tests { use crate::element::Value::*; use crate::element::{Element, IntoAnnotatedElement}; use crate::ion_data::IonEq; - use crate::types::integer::Int; - use crate::types::timestamp::Timestamp as TS; + use crate::types::Int; + use crate::types::Timestamp as TS; use crate::{IonType, Symbol}; use bigdecimal::BigDecimal; use num_bigint::BigInt; diff --git a/src/ion_hash/representation.rs b/src/ion_hash/representation.rs index 643dfaeb..6c19b4aa 100644 --- a/src/ion_hash/representation.rs +++ b/src/ion_hash/representation.rs @@ -10,9 +10,9 @@ use crate::binary::{self, decimal::DecimalBinaryEncoder, timestamp::TimestampBin use crate::element::{Element, Sequence, Struct}; use crate::ion_hash::element_hasher::ElementHasher; use crate::ion_hash::type_qualifier::type_qualifier_symbol; -use crate::types::decimal::Decimal; -use crate::types::integer::Int; -use crate::{result::IonResult, types::timestamp::Timestamp, IonType, Symbol}; +use crate::types::Decimal; +use crate::types::Int; +use crate::{result::IonResult, types::Timestamp, IonType, Symbol}; use digest::{FixedOutput, Output, Reset, Update}; pub(crate) trait RepresentationEncoder { diff --git a/src/lib.rs b/src/lib.rs index e6620465..fba5d3a9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -188,7 +188,6 @@ mod raw_symbol_token_ref; pub mod reader; mod shared_symbol_table; mod stream_reader; -mod symbol; mod symbol_ref; mod symbol_table; mod system_reader; @@ -204,15 +203,15 @@ pub use raw_symbol_token::RawSymbolToken; #[doc(inline)] pub use raw_symbol_token_ref::RawSymbolTokenRef; -pub use symbol::Symbol; pub use symbol_ref::SymbolRef; pub use symbol_table::SymbolTable; -pub use types::decimal::Decimal; -pub use types::integer::Int; -pub use types::string::Str; -pub use types::timestamp::Timestamp; +pub use types::Decimal; +pub use types::Int; pub use types::IonType; +pub use types::Str; +pub use types::Symbol; +pub use types::Timestamp; pub use ion_data::IonData; diff --git a/src/raw_reader.rs b/src/raw_reader.rs index f97258d7..7a3cc2c4 100644 --- a/src/raw_reader.rs +++ b/src/raw_reader.rs @@ -1,8 +1,8 @@ use crate::element::{Blob, Clob}; use crate::raw_symbol_token::RawSymbolToken; use crate::stream_reader::IonReader; -use crate::types::string::Str; use crate::types::IonType; +use crate::types::Str; use crate::{Decimal, Int, IonResult, Timestamp}; use std::fmt::{Display, Formatter}; use std::io::Read; diff --git a/src/reader.rs b/src/reader.rs index fba4a68e..520d6120 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -12,15 +12,15 @@ use crate::raw_reader::{RawReader, RawStreamItem}; use crate::raw_symbol_token::RawSymbolToken; use crate::result::{decoding_error, decoding_error_raw, IonResult}; use crate::stream_reader::IonReader; -use crate::symbol::Symbol; use crate::symbol_table::SymbolTable; -use crate::types::decimal::Decimal; -use crate::types::integer::Int; -use crate::types::timestamp::Timestamp; +use crate::types::Decimal; +use crate::types::Int; +use crate::types::Symbol; +use crate::types::Timestamp; use crate::{BlockingRawBinaryReader, BlockingRawTextReader, IonType}; use std::fmt::{Display, Formatter}; -use crate::types::string::Str; +use crate::types::Str; /// Configures and constructs new instances of [Reader]. pub struct ReaderBuilder {} diff --git a/src/stream_reader.rs b/src/stream_reader.rs index 29d05b97..de8f9c3d 100644 --- a/src/stream_reader.rs +++ b/src/stream_reader.rs @@ -1,10 +1,10 @@ use crate::element::{Blob, Clob}; use crate::result::IonResult; -use crate::types::decimal::Decimal; -use crate::types::integer::Int; -use crate::types::string::Str; -use crate::types::timestamp::Timestamp; +use crate::types::Decimal; +use crate::types::Int; use crate::types::IonType; +use crate::types::Str; +use crate::types::Timestamp; /** * This trait captures the format-agnostic parser functionality needed to navigate within an Ion @@ -85,7 +85,7 @@ pub trait IonReader { /// error is encountered while reading, returns [crate::IonError]. fn read_i64(&mut self) -> IonResult; - /// Attempts to read the current item as an Ion integer and return it as an [crate::Int]. If the + /// Attempts to read the current item as an Ion integer and return it as an [crate::types::Int]. If the /// current item is not an integer or an IO error is encountered while reading, returns /// [crate::IonError]. fn read_int(&mut self) -> IonResult; diff --git a/src/symbol_table.rs b/src/symbol_table.rs index bdb06362..51b338c8 100644 --- a/src/symbol_table.rs +++ b/src/symbol_table.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use std::sync::Arc; use crate::constants::v1_0; -use crate::symbol::Symbol; +use crate::types::Symbol; use crate::types::SymbolId; /// Stores mappings from Symbol IDs to text and vice-versa. diff --git a/src/system_reader.rs b/src/system_reader.rs index 61f32c86..26ea25e4 100644 --- a/src/system_reader.rs +++ b/src/system_reader.rs @@ -7,12 +7,12 @@ use crate::element::{Blob, Clob}; use crate::raw_reader::{RawReader, RawStreamItem}; use crate::raw_symbol_token::RawSymbolToken; use crate::result::{decoding_error, decoding_error_raw, illegal_operation, IonError, IonResult}; -use crate::symbol::Symbol; use crate::system_reader::LstPosition::*; -use crate::types::decimal::Decimal; -use crate::types::integer::Int; -use crate::types::string::Str; -use crate::types::timestamp::Timestamp; +use crate::types::Decimal; +use crate::types::Int; +use crate::types::Str; +use crate::types::Symbol; +use crate::types::Timestamp; use crate::{BlockingRawBinaryReader, IonReader, IonType, SymbolTable}; /// Tracks where the [SystemReader] is in the process of reading a local symbol table. diff --git a/src/text/non_blocking/raw_text_reader.rs b/src/text/non_blocking/raw_text_reader.rs index 38a3cde8..94fd39e1 100644 --- a/src/text/non_blocking/raw_text_reader.rs +++ b/src/text/non_blocking/raw_text_reader.rs @@ -1,7 +1,7 @@ use std::fmt::Display; use crate::element::{Blob, Clob}; -use crate::types::string::Str; +use crate::types::Str; use nom::Err::{Error, Failure, Incomplete}; use crate::raw_reader::{BufferedRawReader, RawStreamItem}; @@ -20,9 +20,9 @@ use crate::text::parsers::containers::{ }; use crate::text::parsers::top_level::{stream_item, RawTextStreamItem}; use crate::text::text_value::{AnnotatedTextValue, TextValue}; -use crate::types::decimal::Decimal; -use crate::types::integer::Int; -use crate::types::timestamp::Timestamp; +use crate::types::Decimal; +use crate::types::Int; +use crate::types::Timestamp; use crate::IonType; const INITIAL_PARENTS_CAPACITY: usize = 16; @@ -974,8 +974,8 @@ mod reader_tests { use crate::stream_reader::IonReader; use crate::text::non_blocking::raw_text_reader::RawTextReader; use crate::text::text_value::{IntoRawAnnotations, TextValue}; - use crate::types::decimal::Decimal; - use crate::types::timestamp::Timestamp; + use crate::types::Decimal; + use crate::types::Timestamp; use crate::IonType; use crate::RawStreamItem::Nothing; diff --git a/src/text/parsers/containers.rs b/src/text/parsers/containers.rs index 4d152931..863017a9 100644 --- a/src/text/parsers/containers.rs +++ b/src/text/parsers/containers.rs @@ -233,8 +233,8 @@ mod container_parsing_tests { use crate::raw_symbol_token::{local_sid_token, text_token}; use crate::text::parsers::unit_test_support::{parse_test_err, parse_test_ok}; use crate::text::text_value::TextValue; - use crate::types::decimal::Decimal; - use crate::types::integer::Int; + use crate::types::Decimal; + use crate::types::Int; use super::*; diff --git a/src/text/parsers/decimal.rs b/src/text/parsers/decimal.rs index 5afec400..3be2deee 100644 --- a/src/text/parsers/decimal.rs +++ b/src/text/parsers/decimal.rs @@ -13,9 +13,9 @@ use crate::text::parsers::numeric_support::{ }; use crate::text::parsers::stop_character; use crate::text::text_value::TextValue; -use crate::types::coefficient::{Coefficient, Sign}; -use crate::types::decimal::Decimal; -use crate::types::integer::UInt; +use crate::types::Decimal; +use crate::types::UInt; +use crate::types::{Coefficient, Sign}; /// Matches the text representation of a decimal value and returns the resulting [Decimal] /// as a [TextValue::Decimal]. @@ -123,7 +123,7 @@ mod reader_tests { use crate::text::parsers::decimal::parse_decimal; use crate::text::parsers::unit_test_support::{parse_test_err, parse_test_ok}; use crate::text::text_value::TextValue; - use crate::types::decimal::Decimal; + use crate::types::Decimal; fn parse_equals(text: &str, expected: Decimal) { parse_test_ok(parse_decimal, text, TextValue::Decimal(expected)) diff --git a/src/text/parsers/integer.rs b/src/text/parsers/integer.rs index c7a03e2b..a58627e5 100644 --- a/src/text/parsers/integer.rs +++ b/src/text/parsers/integer.rs @@ -4,7 +4,7 @@ use crate::text::parse_result::{ use crate::text::parsers::numeric_support::base_10_integer_digits; use crate::text::parsers::stop_character; use crate::text::text_value::TextValue; -use crate::types::integer::Int; +use crate::types::Int; use nom::branch::alt; use nom::bytes::streaming::{is_a, tag, take_while1}; use nom::character::streaming::char; diff --git a/src/text/parsers/timestamp.rs b/src/text/parsers/timestamp.rs index 089f5b46..2cb7e6d8 100644 --- a/src/text/parsers/timestamp.rs +++ b/src/text/parsers/timestamp.rs @@ -14,8 +14,8 @@ use crate::text::parse_result::{ }; use crate::text::parsers::{stop_character, trim_zeros_and_parse_i32, trim_zeros_and_parse_u32}; use crate::text::text_value::TextValue; -use crate::types::decimal::Decimal; -use crate::types::timestamp::{FractionalSecondSetter, Timestamp}; +use crate::types::Decimal; +use crate::types::{FractionalSecondSetter, Timestamp}; /// Matches the text representation of a timestamp value and returns the resulting Timestamp /// as a [TextValue::Timestamp]. @@ -282,8 +282,8 @@ mod reader_tests { use crate::text::parsers::timestamp::parse_timestamp; use crate::text::parsers::unit_test_support::{parse_test_err, parse_test_ok}; use crate::text::text_value::TextValue; - use crate::types::decimal::Decimal; - use crate::types::timestamp::Timestamp; + use crate::types::Decimal; + use crate::types::Timestamp; fn parse_equals(text: &str, expected: Timestamp) { parse_test_ok(parse_timestamp, text, TextValue::Timestamp(expected)) diff --git a/src/text/parsers/top_level.rs b/src/text/parsers/top_level.rs index 3f5f7223..3fc82aba 100644 --- a/src/text/parsers/top_level.rs +++ b/src/text/parsers/top_level.rs @@ -90,7 +90,7 @@ mod parse_top_level_values_tests { use crate::text::parsers::unit_test_support::{parse_test_err, parse_test_ok, parse_unwrap}; use crate::text::parsers::value::value; use crate::text::text_value::TextValue; - use crate::types::integer::Int; + use crate::types::Int; use crate::IonType; use super::*; diff --git a/src/text/raw_text_writer.rs b/src/text/raw_text_writer.rs index 2f029db1..823cd7cd 100644 --- a/src/text/raw_text_writer.rs +++ b/src/text/raw_text_writer.rs @@ -6,9 +6,9 @@ use chrono::{DateTime, FixedOffset}; use crate::raw_symbol_token_ref::{AsRawSymbolTokenRef, RawSymbolTokenRef}; use crate::result::{illegal_operation, IonResult}; use crate::text::text_formatter::STRING_ESCAPE_CODES; -use crate::types::decimal::Decimal; -use crate::types::timestamp::Timestamp; use crate::types::ContainerType; +use crate::types::Decimal; +use crate::types::Timestamp; use crate::writer::IonWriter; use crate::{Int, IonType, RawSymbolToken}; @@ -743,7 +743,7 @@ mod tests { use crate::result::IonResult; use crate::text::raw_text_writer::{RawTextWriter, RawTextWriterBuilder}; - use crate::types::timestamp::Timestamp; + use crate::types::Timestamp; use crate::writer::IonWriter; use crate::IonType; diff --git a/src/text/text_value.rs b/src/text/text_value.rs index 554634b6..c8e75280 100644 --- a/src/text/text_value.rs +++ b/src/text/text_value.rs @@ -1,7 +1,7 @@ use crate::raw_symbol_token::RawSymbolToken; -use crate::types::decimal::Decimal; -use crate::types::integer::Int; -use crate::types::timestamp::Timestamp; +use crate::types::Decimal; +use crate::types::Int; +use crate::types::Timestamp; use crate::IonType; #[derive(Debug, Clone, PartialEq)] diff --git a/src/text/text_writer.rs b/src/text/text_writer.rs index 2ccfe5de..78df80c5 100644 --- a/src/text/text_writer.rs +++ b/src/text/text_writer.rs @@ -2,8 +2,8 @@ use crate::element::writer::TextKind; use crate::raw_symbol_token_ref::{AsRawSymbolTokenRef, RawSymbolTokenRef}; use crate::result::IonResult; use crate::text::raw_text_writer::RawTextWriter; -use crate::types::decimal::Decimal; -use crate::types::timestamp::Timestamp; +use crate::types::Decimal; +use crate::types::Timestamp; use crate::writer::IonWriter; use crate::{Int, IonType, RawTextWriterBuilder, SymbolTable}; use delegate::delegate; diff --git a/src/element/bytes.rs b/src/types/bytes.rs similarity index 100% rename from src/element/bytes.rs rename to src/types/bytes.rs diff --git a/src/types/coefficient.rs b/src/types/coefficient.rs index 9fe90968..9729631f 100644 --- a/src/types/coefficient.rs +++ b/src/types/coefficient.rs @@ -2,7 +2,7 @@ use num_bigint::{BigInt, BigUint}; use num_traits::Zero; use crate::result::{illegal_operation, IonError}; -use crate::types::integer::UInt; +use crate::types::UInt; use std::convert::TryFrom; use std::fmt::{Display, Formatter}; use std::ops::{MulAssign, Neg}; @@ -159,8 +159,8 @@ mod coefficient_tests { use crate::ion_data::IonEq; use num_bigint::BigUint; - use crate::types::coefficient::Coefficient; - use crate::types::decimal::Decimal; + use crate::types::Coefficient; + use crate::types::Decimal; fn eq_test(c1: I1, c2: I2) where diff --git a/src/types/decimal.rs b/src/types/decimal.rs index d701ab6d..25cfa1e0 100644 --- a/src/types/decimal.rs +++ b/src/types/decimal.rs @@ -6,8 +6,8 @@ use num_bigint::{BigInt, BigUint, ToBigUint}; use crate::ion_data::IonEq; use crate::ion_data::IonOrd; use crate::result::{illegal_operation, IonError}; -use crate::types::coefficient::{Coefficient, Sign}; -use crate::types::integer::UInt; +use crate::types::UInt; +use crate::types::{Coefficient, Sign}; use num_traits::Zero; use std::convert::{TryFrom, TryInto}; use std::fmt::{Display, Formatter}; @@ -387,8 +387,8 @@ impl TryFrom for BigDecimal { #[cfg(test)] mod decimal_tests { use crate::result::IonResult; - use crate::types::coefficient::{Coefficient, Sign}; - use crate::types::decimal::Decimal; + use crate::types::Decimal; + use crate::types::{Coefficient, Sign}; use bigdecimal::BigDecimal; use num_bigint::BigUint; use num_traits::{Float, ToPrimitive}; diff --git a/src/types/integer.rs b/src/types/integer.rs index 6dfb1a82..101616dc 100644 --- a/src/types/integer.rs +++ b/src/types/integer.rs @@ -16,7 +16,7 @@ pub trait IntAccess { /// ``` /// # use ion_rs::element::*; /// # use ion_rs::element::*; - /// # use ion_rs::types::integer::*; + /// # use ion_rs::types::*; /// # use num_bigint::*; /// let big_int = Int::BigInt(BigInt::from(100)); /// let i64_int = Int::I64(100); @@ -39,7 +39,7 @@ pub trait IntAccess { /// ``` /// # use ion_rs::element::*; /// # use ion_rs::element::*; - /// # use ion_rs::types::integer::*; + /// # use ion_rs::types::*; /// # use num_bigint::*; /// # use std::str::FromStr; /// let big_int = Int::BigInt(BigInt::from(100)); @@ -509,8 +509,8 @@ mod integer_tests { use num_bigint::BigUint; use num_traits::Zero; // The 'Big' alias helps distinguish between the enum variant and the wrapped numeric type - use crate::types::integer::Int::{self, BigInt as Big, I64}; - use crate::types::integer::UInt; + use crate::types::Int::{self, BigInt as Big, I64}; + use crate::types::UInt; use rstest::*; use std::cmp::Ordering; diff --git a/src/element/iterators.rs b/src/types/iterators.rs similarity index 96% rename from src/element/iterators.rs rename to src/types/iterators.rs index 5f063c2e..b4974147 100644 --- a/src/element/iterators.rs +++ b/src/types/iterators.rs @@ -99,9 +99,9 @@ impl<'a> Iterator for FieldIterator<'a> { /// Iterates over the values associated with a given field name in a Struct. pub struct FieldValuesIterator<'a> { - pub(super) current: usize, - pub(super) indexes: Option<&'a IndexVec>, - pub(super) by_index: &'a Vec<(Symbol, Element)>, + pub(crate) current: usize, + pub(crate) indexes: Option<&'a IndexVec>, + pub(crate) by_index: &'a Vec<(Symbol, Element)>, } impl<'a> Iterator for FieldValuesIterator<'a> { diff --git a/src/element/list.rs b/src/types/list.rs similarity index 96% rename from src/element/list.rs rename to src/types/list.rs index 74beecb3..b3a63114 100644 --- a/src/element/list.rs +++ b/src/types/list.rs @@ -1,8 +1,8 @@ use crate::element::builders::SequenceBuilder; -use crate::element::iterators::ElementsIterator; use crate::element::{Element, Sequence}; use crate::ion_data::IonEq; use crate::text::text_formatter::IonValueFormatter; +use crate::types::iterators::ElementsIterator; use delegate::delegate; use std::fmt::{Display, Formatter}; @@ -86,7 +86,7 @@ impl From for Sequence { #[cfg(test)] mod tests { use crate::ion_list; - use crate::types::integer::IntAccess; + use crate::types::IntAccess; #[test] fn for_element_in_list() { diff --git a/src/element/lob.rs b/src/types/lob.rs similarity index 100% rename from src/element/lob.rs rename to src/types/lob.rs diff --git a/src/types/mod.rs b/src/types/mod.rs index c98c2a2c..4763b4af 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -4,11 +4,35 @@ pub type SymbolId = usize; -pub mod coefficient; -pub mod decimal; -pub mod integer; -pub mod string; -pub mod timestamp; +mod bytes; +mod coefficient; +mod decimal; +mod integer; +pub mod iterators; +mod list; +mod lob; +mod sequence; +mod sexp; +mod string; +mod r#struct; +mod symbol; +mod timestamp; + +pub use crate::types::bytes::Bytes; +pub use coefficient::{Coefficient, Sign}; +pub use decimal::Decimal; +pub use integer::{Int, IntAccess, UInt}; +pub use list::List; +pub use lob::{Blob, Clob}; +pub use r#struct::Struct; +pub use sequence::Sequence; +pub use sexp::SExp; +pub use string::Str; +pub use symbol::Symbol; +pub use timestamp::{ + DaySetter, FractionalSecondSetter, HourAndMinuteSetter, Mantissa, MonthSetter, Precision, + SecondSetter, Timestamp, +}; use crate::ion_data::IonOrd; use std::cmp::Ordering; diff --git a/src/element/sequence.rs b/src/types/sequence.rs similarity index 97% rename from src/element/sequence.rs rename to src/types/sequence.rs index 0d4fd01b..0b0dfa25 100644 --- a/src/element/sequence.rs +++ b/src/types/sequence.rs @@ -1,7 +1,7 @@ use crate::element::builders::SequenceBuilder; -use crate::element::iterators::ElementsIterator; use crate::element::Element; use crate::ion_data::{IonEq, IonOrd}; +use crate::types::iterators::ElementsIterator; use std::cmp::Ordering; #[derive(Debug, Clone, PartialEq, Eq)] diff --git a/src/element/sexp.rs b/src/types/sexp.rs similarity index 96% rename from src/element/sexp.rs rename to src/types/sexp.rs index 96c539b7..68b870db 100644 --- a/src/element/sexp.rs +++ b/src/types/sexp.rs @@ -1,8 +1,8 @@ use crate::element::builders::SequenceBuilder; -use crate::element::iterators::ElementsIterator; use crate::element::{Element, Sequence}; use crate::ion_data::IonEq; use crate::text::text_formatter::IonValueFormatter; +use crate::types::iterators::ElementsIterator; use delegate::delegate; use std::fmt::{Display, Formatter}; @@ -86,7 +86,7 @@ impl From for Sequence { #[cfg(test)] mod tests { use crate::ion_sexp; - use crate::types::integer::IntAccess; + use crate::types::IntAccess; #[test] fn for_element_in_sexp() { diff --git a/src/element/struct.rs b/src/types/struct.rs similarity index 99% rename from src/element/struct.rs rename to src/types/struct.rs index b9b3a35d..50a88762 100644 --- a/src/element/struct.rs +++ b/src/types/struct.rs @@ -1,9 +1,9 @@ use crate::element::builders::StructBuilder; -use crate::element::iterators::{FieldIterator, FieldValuesIterator, IndexVec}; use crate::element::Element; use crate::ion_data::{IonEq, IonOrd}; use crate::symbol_ref::AsSymbolRef; use crate::text::text_formatter::IonValueFormatter; +use crate::types::iterators::{FieldIterator, FieldValuesIterator, IndexVec}; use crate::Symbol; use std::cmp::Ordering; use std::collections::HashMap; diff --git a/src/symbol.rs b/src/types/symbol.rs similarity index 100% rename from src/symbol.rs rename to src/types/symbol.rs diff --git a/src/types/timestamp.rs b/src/types/timestamp.rs index be8e6a1b..a609fa4d 100644 --- a/src/types/timestamp.rs +++ b/src/types/timestamp.rs @@ -3,9 +3,9 @@ use crate::ion_data::IonOrd; use crate::result::{ encoding_error, illegal_operation, illegal_operation_raw, IonError, IonResult, }; -use crate::types::coefficient::Sign::Negative; -use crate::types::decimal::Decimal; -use crate::types::integer::UInt; +use crate::types::Decimal; +use crate::types::Sign::Negative; +use crate::types::UInt; use chrono::{ DateTime, Datelike, FixedOffset, LocalResult, NaiveDate, NaiveDateTime, TimeZone, Timelike, }; @@ -1316,8 +1316,8 @@ mod timestamp_tests { use super::*; use crate::ion_data::IonEq; use crate::result::IonResult; - use crate::types::decimal::Decimal; - use crate::types::timestamp::{Mantissa, Precision, Timestamp}; + use crate::types::Decimal; + use crate::types::{Mantissa, Precision, Timestamp}; use chrono::{DateTime, FixedOffset, NaiveDate, NaiveDateTime, TimeZone, Timelike}; use rstest::*; use std::cmp::Ordering; diff --git a/src/writer.rs b/src/writer.rs index d31cc2d7..59fa2734 100644 --- a/src/writer.rs +++ b/src/writer.rs @@ -1,9 +1,9 @@ use crate::raw_symbol_token_ref::AsRawSymbolTokenRef; use crate::result::IonResult; -use crate::types::decimal::Decimal; -use crate::types::timestamp::Timestamp; +use crate::types::Decimal; +use crate::types::Int; use crate::types::IonType; -use crate::Int; +use crate::types::Timestamp; /** * This trait captures the format-agnostic encoding functionality needed to write native Rust types diff --git a/tests/ion_hash_tests.rs b/tests/ion_hash_tests.rs index 86723381..04cf462b 100644 --- a/tests/ion_hash_tests.rs +++ b/tests/ion_hash_tests.rs @@ -7,7 +7,7 @@ use ion_rs::element::writer::ElementWriter; use ion_rs::element::{Element, Struct}; use ion_rs::ion_hash::IonHasher; use ion_rs::result::{illegal_operation, IonResult}; -use ion_rs::types::integer::IntAccess; +use ion_rs::types::IntAccess; use ion_rs::IonWriter; use std::convert::From; diff --git a/tests/reexport_external.rs b/tests/reexport_external.rs index 925ea35f..2e923cfa 100644 --- a/tests/reexport_external.rs +++ b/tests/reexport_external.rs @@ -1,7 +1,7 @@ use std::convert::TryInto; use ion_rs::external::bigdecimal::{BigDecimal, Zero}; -use ion_rs::types::decimal::Decimal; +use ion_rs::types::Decimal; /// This test shows how the ion_rs integration with bigdecimal can be used /// through a reexport. This means that consumers of ion_rs can use this From b4c35213b87d2fbd5ef922cd638b776e62b2a614 Mon Sep 17 00:00:00 2001 From: Matthew Pope <81593196+popematt@users.noreply.github.com> Date: Mon, 1 May 2023 10:41:23 -0700 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Almann Goo --- src/binary/non_blocking/binary_buffer.rs | 4 ++-- src/stream_reader.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/binary/non_blocking/binary_buffer.rs b/src/binary/non_blocking/binary_buffer.rs index d1044b7a..e3c10b7d 100644 --- a/src/binary/non_blocking/binary_buffer.rs +++ b/src/binary/non_blocking/binary_buffer.rs @@ -7,8 +7,8 @@ use crate::binary::uint::DecodedUInt; use crate::binary::var_int::VarInt; use crate::binary::var_uint::VarUInt; use crate::result::{decoding_error, incomplete_data_error, incomplete_data_error_raw}; -use crate::types::UInt; -use crate::{types::Int, IonResult, IonType}; +use crate::types::{Int, UInt}; +use crate::{IonResult, IonType}; use num_bigint::{BigInt, BigUint, Sign}; use std::io::Read; use std::mem; diff --git a/src/stream_reader.rs b/src/stream_reader.rs index de8f9c3d..4b90e2ac 100644 --- a/src/stream_reader.rs +++ b/src/stream_reader.rs @@ -85,7 +85,7 @@ pub trait IonReader { /// error is encountered while reading, returns [crate::IonError]. fn read_i64(&mut self) -> IonResult; - /// Attempts to read the current item as an Ion integer and return it as an [crate::types::Int]. If the + /// Attempts to read the current item as an Ion integer and return it as an [`Int`](crate::types::Int). If the /// current item is not an integer or an IO error is encountered while reading, returns /// [crate::IonError]. fn read_int(&mut self) -> IonResult; From 4a440afb97d8ebcc4501cf636363b9f923274ba6 Mon Sep 17 00:00:00 2001 From: Matthew Pope Date: Mon, 1 May 2023 10:56:10 -0700 Subject: [PATCH 3/3] Move ElementIterator and SymbolsIterator back to `elements` module --- src/element/annotations.rs | 2 +- src/element/element_stream_reader.rs | 2 +- src/{types => element}/iterators.rs | 54 --------------------------- src/element/mod.rs | 1 + src/types/list.rs | 2 +- src/types/mod.rs | 1 - src/types/sequence.rs | 2 +- src/types/sexp.rs | 2 +- src/types/struct.rs | 55 +++++++++++++++++++++++++++- 9 files changed, 60 insertions(+), 61 deletions(-) rename src/{types => element}/iterators.rs (58%) diff --git a/src/element/annotations.rs b/src/element/annotations.rs index f584a012..58ebb376 100644 --- a/src/element/annotations.rs +++ b/src/element/annotations.rs @@ -1,5 +1,5 @@ +use crate::element::iterators::{AnnotationsIntoIter, SymbolsIterator}; use crate::ion_data::IonOrd; -use crate::types::iterators::{AnnotationsIntoIter, SymbolsIterator}; use crate::Symbol; use std::cmp::Ordering; diff --git a/src/element/element_stream_reader.rs b/src/element/element_stream_reader.rs index 497db4b2..dd9a7848 100644 --- a/src/element/element_stream_reader.rs +++ b/src/element/element_stream_reader.rs @@ -1,8 +1,8 @@ use crate::result::{decoding_error, illegal_operation, illegal_operation_raw}; use crate::text::parent_container::ParentContainer; +use crate::element::iterators::SymbolsIterator; use crate::element::{Blob, Clob, Element}; -use crate::types::iterators::SymbolsIterator; use crate::{ Decimal, Int, IonError, IonReader, IonResult, IonType, Str, StreamItem, Symbol, Timestamp, }; diff --git a/src/types/iterators.rs b/src/element/iterators.rs similarity index 58% rename from src/types/iterators.rs rename to src/element/iterators.rs index b4974147..d9f11e68 100644 --- a/src/types/iterators.rs +++ b/src/element/iterators.rs @@ -1,6 +1,5 @@ use crate::element::Element; use crate::Symbol; -use smallvec::SmallVec; // This macro defines a new iterator type for a given `Iterator => Item` type name pair. // // The implementation produced can be used to iterate over any `Vec` or `&[Item]`. @@ -64,56 +63,3 @@ impl Iterator for AnnotationsIntoIter { self.into_iter.next() } } - -// A convenient type alias for a vector capable of storing a single `usize` inline -// without heap allocation. This type should not be used in public interfaces directly. -pub(crate) type IndexVec = SmallVec<[usize; 1]>; - -/// Iterates over the (field name, field value) pairs in a Struct. -pub struct FieldIterator<'a> { - values: Option>, -} - -impl<'a> FieldIterator<'a> { - pub(crate) fn new(data: &'a [(Symbol, Element)]) -> Self { - FieldIterator { - values: Some(data.iter()), - } - } - - pub(crate) fn empty() -> FieldIterator<'static> { - FieldIterator { values: None } - } -} - -impl<'a> Iterator for FieldIterator<'a> { - type Item = (&'a Symbol, &'a Element); - - fn next(&mut self) -> Option { - self.values - .as_mut() - // Get the next &(name, value) and convert it to (&name, &value) - .and_then(|iter| iter.next().map(|field| (&field.0, &field.1))) - } -} - -/// Iterates over the values associated with a given field name in a Struct. -pub struct FieldValuesIterator<'a> { - pub(crate) current: usize, - pub(crate) indexes: Option<&'a IndexVec>, - pub(crate) by_index: &'a Vec<(Symbol, Element)>, -} - -impl<'a> Iterator for FieldValuesIterator<'a> { - type Item = &'a Element; - - fn next(&mut self) -> Option { - self.indexes - .and_then(|i| i.get(self.current)) - .and_then(|i| { - self.current += 1; - self.by_index.get(*i) - }) - .map(|(_name, value)| value) - } -} diff --git a/src/element/mod.rs b/src/element/mod.rs index a5d3ebf8..226386e0 100644 --- a/src/element/mod.rs +++ b/src/element/mod.rs @@ -26,6 +26,7 @@ use std::fmt::{Display, Formatter}; mod annotations; pub mod builders; mod element_stream_reader; +pub(crate) mod iterators; pub mod reader; pub mod writer; diff --git a/src/types/list.rs b/src/types/list.rs index b3a63114..f0e626a0 100644 --- a/src/types/list.rs +++ b/src/types/list.rs @@ -1,8 +1,8 @@ use crate::element::builders::SequenceBuilder; +use crate::element::iterators::ElementsIterator; use crate::element::{Element, Sequence}; use crate::ion_data::IonEq; use crate::text::text_formatter::IonValueFormatter; -use crate::types::iterators::ElementsIterator; use delegate::delegate; use std::fmt::{Display, Formatter}; diff --git a/src/types/mod.rs b/src/types/mod.rs index 4763b4af..e6c27b2f 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -8,7 +8,6 @@ mod bytes; mod coefficient; mod decimal; mod integer; -pub mod iterators; mod list; mod lob; mod sequence; diff --git a/src/types/sequence.rs b/src/types/sequence.rs index 0b0dfa25..0d4fd01b 100644 --- a/src/types/sequence.rs +++ b/src/types/sequence.rs @@ -1,7 +1,7 @@ use crate::element::builders::SequenceBuilder; +use crate::element::iterators::ElementsIterator; use crate::element::Element; use crate::ion_data::{IonEq, IonOrd}; -use crate::types::iterators::ElementsIterator; use std::cmp::Ordering; #[derive(Debug, Clone, PartialEq, Eq)] diff --git a/src/types/sexp.rs b/src/types/sexp.rs index 68b870db..ae7408f8 100644 --- a/src/types/sexp.rs +++ b/src/types/sexp.rs @@ -1,8 +1,8 @@ use crate::element::builders::SequenceBuilder; +use crate::element::iterators::ElementsIterator; use crate::element::{Element, Sequence}; use crate::ion_data::IonEq; use crate::text::text_formatter::IonValueFormatter; -use crate::types::iterators::ElementsIterator; use delegate::delegate; use std::fmt::{Display, Formatter}; diff --git a/src/types/struct.rs b/src/types/struct.rs index 50a88762..a866060f 100644 --- a/src/types/struct.rs +++ b/src/types/struct.rs @@ -3,12 +3,16 @@ use crate::element::Element; use crate::ion_data::{IonEq, IonOrd}; use crate::symbol_ref::AsSymbolRef; use crate::text::text_formatter::IonValueFormatter; -use crate::types::iterators::{FieldIterator, FieldValuesIterator, IndexVec}; use crate::Symbol; +use smallvec::SmallVec; use std::cmp::Ordering; use std::collections::HashMap; use std::fmt::{Display, Formatter}; +// A convenient type alias for a vector capable of storing a single `usize` inline +// without heap allocation. This type should not be used in public interfaces directly. +type IndexVec = SmallVec<[usize; 1]>; + // This collection is broken out into its own type to allow instances of it to be shared with Arc/Rc. #[derive(Debug, Clone)] struct Fields { @@ -76,6 +80,55 @@ impl Fields { } } +/// Iterates over the (field name, field value) pairs in a Struct. +pub struct FieldIterator<'a> { + values: Option>, +} + +impl<'a> FieldIterator<'a> { + fn new(data: &'a [(Symbol, Element)]) -> Self { + FieldIterator { + values: Some(data.iter()), + } + } + + fn empty() -> FieldIterator<'static> { + FieldIterator { values: None } + } +} + +impl<'a> Iterator for FieldIterator<'a> { + type Item = (&'a Symbol, &'a Element); + + fn next(&mut self) -> Option { + self.values + .as_mut() + // Get the next &(name, value) and convert it to (&name, &value) + .and_then(|iter| iter.next().map(|field| (&field.0, &field.1))) + } +} + +/// Iterates over the values associated with a given field name in a Struct. +pub struct FieldValuesIterator<'a> { + current: usize, + indexes: Option<&'a IndexVec>, + by_index: &'a Vec<(Symbol, Element)>, +} + +impl<'a> Iterator for FieldValuesIterator<'a> { + type Item = &'a Element; + + fn next(&mut self) -> Option { + self.indexes + .and_then(|i| i.get(self.current)) + .and_then(|i| { + self.current += 1; + self.by_index.get(*i) + }) + .map(|(_name, value)| value) + } +} + /// An in-memory representation of an Ion Struct /// ``` /// use ion_rs::element::Element;