diff --git a/Cargo.toml b/Cargo.toml index 857b1d34..dc3ea10e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -73,7 +73,6 @@ rstest_reuse = "0.6.0" # Used by ion-tests integration walkdir = "2.5.0" test-generator = "0.3" -memmap = "0.7.0" criterion = "0.5.1" rand = "0.8.5" tempfile = "3.10.0" diff --git a/README.md b/README.md index bade5bc9..534a46e2 100644 --- a/README.md +++ b/README.md @@ -10,13 +10,12 @@ A Rust implementation of the [Amazon Ion][spec] data format. ## Example -For more information, please see our [official documentation](https://docs.rs/ion-rs). +For more information, please see the [documentation](https://docs.rs/ion-rs). ```rust -use ion_rs::{Element, IonResult, IonType, ion_seq}; +use crate::{ion_seq, Element, IonResult, Timestamp}; fn main() -> IonResult<()> { - // Read a single value from a string/slice/Vec let element = Element::read_one("\"Hello, world!\"")?; let text = element.expect_string()?; @@ -35,25 +34,23 @@ fn main() -> IonResult<()> { for element in Element::iter(ion_file)? { println!("{}", element?) } - + // Construct a sequence of Ion elements from Rust values let values = ion_seq!( "foo", - Timestamp::with_ymd(2016, 5, 11).build(), + Timestamp::with_ymd(2016, 5, 11).build()?, 3.1416f64, true ); - // Write values to a buffer in generously-spaced text - let mut text_buffer: Vec = Vec::new(); - Element::write_all_as(&values, Format::Text(TextKind::Pretty), &mut text_buffer)?; - assert_eq!(values, Element::read_all(text_buffer)?); + // Write values to a String using generously-spaced text + let text_ion: String = values.encode_as(v1_0::Text.with_format(TextFormat::Pretty))?; + assert_eq!(values, Element::read_all(text_ion)?); // Write values to a buffer in compact binary - let mut binary_buffer: Vec = Vec::new(); - Element::write_all_as(&values, Format::Binary, &mut binary_buffer)?; + let binary_buffer: Vec = values.encode_as(v1_0::Binary)?; assert_eq!(values, Element::read_all(binary_buffer)?); - + Ok(()) } ``` @@ -64,11 +61,10 @@ The `ion_rs` library has a number of features that users can opt into. While the are complete and well-tested, their APIs are not stable and are subject to change without notice between minor versions of the library. -1. `experimental-ion-hash`, an implementation of [Ion Hash][ion-hash-spec]. -2. `experimental-reader`, a streaming reader API. -3. `experimental-writer`, a streaming writer API. - -Features that are defined in `Cargo.toml` but not listed above have not been thoroughly tested. +1. `experimental-reader-writer`, a streaming reader and writer API. +2. `experimental-tooling-apis`, APIs for accessing the encoding-level details of the stream. +3. `experimental-serde`, a `serde` serializer and deserializer. +4. `experimental-ion-hash`, an implementation of [Ion Hash][ion-hash-spec]. ## Development @@ -106,6 +102,9 @@ $ ./clean-rebuild.sh ``` [spec]: https://amazon-ion.github.io/ion-docs/docs/spec.html + [ion-tests]: https://github.com/amazon-ion/ion-tests + [ion-hash-spec]: https://amazon-ion.github.io/ion-hash/docs/spec.html + [ion-hash-tests]: https://github.com/amazon-ion/ion-hash-tests diff --git a/benches/read_many_structs.rs b/benches/read_many_structs.rs index 0992611e..a57f66e8 100644 --- a/benches/read_many_structs.rs +++ b/benches/read_many_structs.rs @@ -12,7 +12,7 @@ mod benchmark { mod benchmark { use criterion::{black_box, Criterion}; use ion_rs::{v1_0, v1_1, ElementReader, Encoding, IonData, IonReader, WriteConfig}; - use ion_rs::{Element, IonResult, LazyDecoder, LazyStruct, LazyValue, ValueRef}; + use ion_rs::{Decoder, Element, IonResult, LazyStruct, LazyValue, ValueRef}; fn rewrite_as( pretty_ion: &str, @@ -24,7 +24,7 @@ mod benchmark { Ok(buffer) } - fn count_value_and_children(lazy_value: &LazyValue<'_, D>) -> IonResult { + fn count_value_and_children(lazy_value: &LazyValue<'_, D>) -> IonResult { use ValueRef::*; let child_count = match lazy_value.read()? { List(s) => count_sequence_children(s.iter())?, @@ -38,7 +38,7 @@ mod benchmark { Ok(1 + child_count) } - fn count_sequence_children<'a, D: LazyDecoder>( + fn count_sequence_children<'a, D: Decoder>( lazy_sequence: impl Iterator>>, ) -> IonResult { let mut count = 0; @@ -48,7 +48,7 @@ mod benchmark { Ok(count) } - fn count_struct_children(lazy_struct: &LazyStruct<'_, D>) -> IonResult { + fn count_struct_children(lazy_struct: &LazyStruct<'_, D>) -> IonResult { let mut count = 0; for field in lazy_struct { count += count_value_and_children(&field?.value())?; diff --git a/benches/write_many_structs.rs b/benches/write_many_structs.rs index dad0f17a..13ebe77a 100644 --- a/benches/write_many_structs.rs +++ b/benches/write_many_structs.rs @@ -11,9 +11,7 @@ mod benchmark { #[cfg(feature = "experimental")] mod benchmark { use criterion::{black_box, Criterion}; - use ion_rs::v1_0::LazyRawBinaryWriter_1_0; - use ion_rs::v1_1::LazyRawBinaryWriter_1_1; - use ion_rs::{IonResult, RawSymbolRef, SequenceWriter, StructWriter, ValueWriter}; + use ion_rs::{v1_0, v1_1, IonResult, RawSymbolRef, SequenceWriter, StructWriter, ValueWriter}; fn write_struct_with_string_values(value_writer: impl ValueWriter) -> IonResult<()> { let mut struct_ = value_writer.struct_writer()?; @@ -131,7 +129,7 @@ mod benchmark { binary_1_0_group.bench_function("write structs with string values", |b| { b.iter(|| { buffer.clear(); - let mut writer = LazyRawBinaryWriter_1_0::new(&mut buffer).unwrap(); + let mut writer = v1_0::RawBinaryWriter::new(&mut buffer).unwrap(); write_struct_with_string_values(writer.value_writer()).unwrap(); writer.flush().unwrap(); black_box(buffer.as_slice()); @@ -149,7 +147,7 @@ mod benchmark { binary_1_0_group.bench_function("write structs with symbol values", |b| { b.iter(|| { buffer.clear(); - let mut writer = LazyRawBinaryWriter_1_0::new(&mut buffer).unwrap(); + let mut writer = v1_0::RawBinaryWriter::new(&mut buffer).unwrap(); write_struct_with_symbol_values(writer.value_writer()).unwrap(); writer.flush().unwrap(); @@ -166,7 +164,7 @@ mod benchmark { binary_1_1_group.bench_function("write structs with string values", |b| { b.iter(|| { buffer.clear(); - let mut writer = LazyRawBinaryWriter_1_1::new(&mut buffer).unwrap(); + let mut writer = v1_1::RawBinaryWriter::new(&mut buffer).unwrap(); write_struct_with_string_values(writer.value_writer()).unwrap(); writer.flush().unwrap(); black_box(buffer.as_slice()); @@ -180,7 +178,7 @@ mod benchmark { binary_1_1_group.bench_function("write structs with symbol values", |b| { b.iter(|| { buffer.clear(); - let mut writer = LazyRawBinaryWriter_1_1::new(&mut buffer).unwrap(); + let mut writer = v1_1::RawBinaryWriter::new(&mut buffer).unwrap(); write_struct_with_symbol_values(writer.value_writer()).unwrap(); writer.flush().unwrap(); @@ -195,7 +193,7 @@ mod benchmark { binary_1_1_group.bench_function("write delimited structs with string values", |b| { b.iter(|| { buffer.clear(); - let mut writer = LazyRawBinaryWriter_1_1::new(&mut buffer).unwrap(); + let mut writer = v1_1::RawBinaryWriter::new(&mut buffer).unwrap(); write_struct_with_string_values(writer.value_writer().with_delimited_containers()) .unwrap(); writer.flush().unwrap(); @@ -213,7 +211,7 @@ mod benchmark { binary_1_1_group.bench_function("write delimited structs with symbol values", |b| { b.iter(|| { buffer.clear(); - let mut writer = LazyRawBinaryWriter_1_1::new(&mut buffer).unwrap(); + let mut writer = v1_1::RawBinaryWriter::new(&mut buffer).unwrap(); write_struct_with_symbol_values(writer.value_writer().with_delimited_containers()) .unwrap(); writer.flush().unwrap(); @@ -229,7 +227,7 @@ mod benchmark { binary_1_1_group.bench_function("write structs with string values using macros", |b| { b.iter(|| { buffer.clear(); - let mut writer = LazyRawBinaryWriter_1_1::new(&mut buffer).unwrap(); + let mut writer = v1_1::RawBinaryWriter::new(&mut buffer).unwrap(); write_eexp_with_string_values(writer.value_writer()).unwrap(); writer.flush().unwrap(); black_box(buffer.as_slice()); @@ -246,7 +244,7 @@ mod benchmark { binary_1_1_group.bench_function("write structs with symbol values using macros", |b| { b.iter(|| { buffer.clear(); - let mut writer = LazyRawBinaryWriter_1_1::new(&mut buffer).unwrap(); + let mut writer = v1_1::RawBinaryWriter::new(&mut buffer).unwrap(); write_eexp_with_symbol_values(writer.value_writer()).unwrap(); writer.flush().unwrap(); black_box(buffer.as_slice()); diff --git a/examples/read_all_values.rs b/examples/read_all_values.rs index c1720871..238a2c12 100644 --- a/examples/read_all_values.rs +++ b/examples/read_all_values.rs @@ -16,9 +16,7 @@ mod lazy_reader_example { use std::fs::File; use std::process::exit; - use memmap::MmapOptions; - - use ion_rs::{v1_0, Encoding, IonResult, LazyStruct, LazyValue, ValueRef}; + use ion_rs::{Decoder, IonResult, LazyStruct, LazyValue, Reader, ValueRef}; pub fn read_all_values() -> IonResult<()> { let args: Vec = std::env::args().collect(); @@ -29,15 +27,10 @@ mod lazy_reader_example { }); let file = File::open(path).unwrap(); - - // This example uses `mmap` so we can view the entire input file as a `&[u8]`. - let mmap = unsafe { MmapOptions::new().map(&file).unwrap() }; - let ion_data: &[u8] = &mmap[..]; - + let mut reader = Reader::new(file)?; // We're going to recursively visit and read every value in the input stream, counting // them as we go. let mut count = 0; - let mut reader = v1_0::BinaryReader::new(ion_data)?; while let Some(lazy_value) = reader.next()? { count += count_value_and_children(&lazy_value)?; } @@ -46,7 +39,7 @@ mod lazy_reader_example { } // Counts scalar values as 1 and container values as (the number of children) + 1. - fn count_value_and_children(lazy_value: &LazyValue) -> IonResult { + fn count_value_and_children(lazy_value: &LazyValue) -> IonResult { use ValueRef::*; let child_count = match lazy_value.read()? { List(s) => count_sequence_children(s.iter())?, @@ -57,8 +50,8 @@ mod lazy_reader_example { Ok(1 + child_count) } - fn count_sequence_children<'a, E: Encoding>( - lazy_sequence: impl Iterator>>, + fn count_sequence_children<'a, D: Decoder>( + lazy_sequence: impl Iterator>>, ) -> IonResult { let mut count = 0; for value in lazy_sequence { @@ -67,7 +60,7 @@ mod lazy_reader_example { Ok(count) } - fn count_struct_children(lazy_struct: &LazyStruct) -> IonResult { + fn count_struct_children(lazy_struct: &LazyStruct) -> IonResult { let mut count = 0; for field in lazy_struct { count += count_value_and_children(&field?.value())?; diff --git a/src/binary/decimal.rs b/src/binary/decimal.rs index bea1c4e8..062bc64c 100644 --- a/src/binary/decimal.rs +++ b/src/binary/decimal.rs @@ -107,7 +107,7 @@ where #[cfg(test)] mod binary_decimal_tests { - use crate::lazy::encoder::writer::IonWriter; + use crate::lazy::encoder::writer::Writer; use crate::lazy::encoding::{BinaryEncoding_1_0, Encoding}; use crate::lazy::reader::Reader; use rstest::*; @@ -152,10 +152,10 @@ mod binary_decimal_tests { #[case::foo(Decimal::new(i128::MIN + 1, i32::MIN))] fn roundtrip_decimals_with_extreme_values(#[case] value: Decimal) -> IonResult<()> { let mut writer = - IonWriter::with_config(BinaryEncoding_1_0::default_write_config(), Vec::new())?; + Writer::with_config(BinaryEncoding_1_0::default_write_config(), Vec::new())?; writer.write(value)?; let output = writer.close()?; - let mut reader = Reader::new(output); + let mut reader = Reader::new(output)?; let after_round_trip = reader.expect_next()?.read()?.expect_decimal()?; assert_eq!(value, after_round_trip); Ok(()) diff --git a/src/binary/timestamp.rs b/src/binary/timestamp.rs index 8bdf0bf7..e46dd6dc 100644 --- a/src/binary/timestamp.rs +++ b/src/binary/timestamp.rs @@ -147,7 +147,7 @@ mod binary_timestamp_tests { #[case] input: &str, #[case] expected: usize, ) -> IonResult<()> { - let mut reader = Reader::new(input); + let mut reader = Reader::new(input)?; let timestamp = reader.expect_next()?.read()?.expect_timestamp()?; let mut buf = vec![]; let written = buf.encode_timestamp_value(×tamp)?; diff --git a/src/element/mod.rs b/src/element/mod.rs index 83f13f2c..a4d77cdf 100644 --- a/src/element/mod.rs +++ b/src/element/mod.rs @@ -653,14 +653,14 @@ impl Element { /// If the data source has at least one value, returns `Ok(Some(Element))`. /// If the data source has invalid data, returns `Err`. pub fn read_first>(data: A) -> IonResult> { - let mut reader = Reader::new(IonSlice::new(data)); + let mut reader = Reader::new(IonSlice::new(data))?; reader.read_next_element() } /// Reads a single Ion [`Element`] from the provided data source. If the input has invalid /// data or does not contain at exactly one Ion value, returns `Err(IonError)`. pub fn read_one>(data: A) -> IonResult { - let mut reader = Reader::new(IonSlice::new(data)); + let mut reader = Reader::new(IonSlice::new(data))?; reader.read_one_element() } @@ -669,7 +669,7 @@ impl Element { /// If the input has valid data, returns `Ok(Sequence)`. /// If the input has invalid data, returns `Err(IonError)`. pub fn read_all>(data: A) -> IonResult { - Ok(Reader::new(IonSlice::new(data)) + Ok(Reader::new(IonSlice::new(data))? .into_elements() .collect::>>()? .into()) @@ -681,7 +681,7 @@ impl Element { pub fn iter<'a, I: IonInput + 'a>( source: I, ) -> IonResult> + 'a> { - Ok(Reader::new(source).into_elements()) + Ok(Reader::new(source)?.into_elements()) } /// Encodes this element as an Ion stream with itself as the only top-level value. diff --git a/src/lazy/any_encoding.rs b/src/lazy/any_encoding.rs index d7304bc2..0a05e9d2 100644 --- a/src/lazy/any_encoding.rs +++ b/src/lazy/any_encoding.rs @@ -28,7 +28,7 @@ use crate::lazy::binary::raw::v1_1::RawBinaryAnnotationsIterator_1_1; use crate::lazy::binary::raw::value::{LazyRawBinaryValue_1_0, LazyRawBinaryVersionMarker_1_0}; use crate::lazy::decoder::private::LazyContainerPrivate; use crate::lazy::decoder::{ - HasRange, HasSpan, LazyDecoder, LazyRawContainer, LazyRawFieldExpr, LazyRawFieldName, + Decoder, HasRange, HasSpan, LazyRawContainer, LazyRawFieldExpr, LazyRawFieldName, LazyRawReader, LazyRawSequence, LazyRawStruct, LazyRawValue, LazyRawValueExpr, RawValueExpr, RawVersionMarker, }; @@ -65,7 +65,7 @@ pub struct AnyEncoding; // This family of types avoids boxing and dynamic dispatch by using enums of the supported formats // within each type. Trait methods are implemented by forwarding the call to the appropriate // underlying type. -impl LazyDecoder for AnyEncoding { +impl Decoder for AnyEncoding { type Reader<'data> = LazyRawAnyReader<'data>; type ReaderSavedState = RawReaderType; type Value<'top> = LazyRawAnyValue<'top>; @@ -358,7 +358,7 @@ impl<'data> LazyRawReader<'data, AnyEncoding> for LazyRawAnyReader<'data> { } #[inline] - fn save_state(&self) -> ::ReaderSavedState { + fn save_state(&self) -> ::ReaderSavedState { use RawReaderKind::*; match &self.encoding { Text_1_0(_) => RawReaderType::Text_1_0, @@ -837,7 +837,7 @@ impl<'data> Iterator for RawAnyListIterator<'data> { } impl<'top> LazyRawContainer<'top, AnyEncoding> for LazyRawAnyList<'top> { - fn as_value(&self) -> ::Value<'top> { + fn as_value(&self) -> ::Value<'top> { match &self.encoding { LazyRawListKind::Text_1_0(s) => s.as_value().into(), LazyRawListKind::Binary_1_0(s) => s.as_value().into(), @@ -850,7 +850,7 @@ impl<'top> LazyRawContainer<'top, AnyEncoding> for LazyRawAnyList<'top> { impl<'top> LazyRawSequence<'top, AnyEncoding> for LazyRawAnyList<'top> { type Iterator = RawAnyListIterator<'top>; - fn annotations(&self) -> ::AnnotationsIterator<'top> { + fn annotations(&self) -> ::AnnotationsIterator<'top> { self.as_value().annotations() } @@ -935,7 +935,7 @@ pub enum LazyRawSExpKind<'data> { } impl<'top> LazyRawContainer<'top, AnyEncoding> for LazyRawAnySExp<'top> { - fn as_value(&self) -> ::Value<'top> { + fn as_value(&self) -> ::Value<'top> { use LazyRawSExpKind::*; match self.encoding { Text_1_0(s) => s.as_value().into(), @@ -1000,7 +1000,7 @@ impl<'data> Iterator for RawAnySExpIterator<'data> { impl<'top> LazyRawSequence<'top, AnyEncoding> for LazyRawAnySExp<'top> { type Iterator = RawAnySExpIterator<'top>; - fn annotations(&self) -> ::AnnotationsIterator<'top> { + fn annotations(&self) -> ::AnnotationsIterator<'top> { self.as_value().annotations() } @@ -1079,7 +1079,7 @@ pub enum LazyRawStructKind<'data> { } impl<'top> LazyRawContainer<'top, AnyEncoding> for LazyRawAnyStruct<'top> { - fn as_value(&self) -> ::Value<'top> { + fn as_value(&self) -> ::Value<'top> { match self.encoding { LazyRawStructKind::Text_1_0(s) => s.as_value().into(), LazyRawStructKind::Binary_1_0(s) => s.as_value().into(), @@ -1274,7 +1274,7 @@ impl<'data> LazyContainerPrivate<'data, AnyEncoding> for LazyRawAnyStruct<'data> impl<'top> LazyRawStruct<'top, AnyEncoding> for LazyRawAnyStruct<'top> { type Iterator = RawAnyStructIterator<'top>; - fn annotations(&self) -> ::AnnotationsIterator<'top> { + fn annotations(&self) -> ::AnnotationsIterator<'top> { match &self.encoding { LazyRawStructKind::Text_1_0(s) => RawAnyAnnotationsIterator { encoding: RawAnnotationsIteratorKind::Text_1_0(s.annotations()), diff --git a/src/lazy/binary/encoded_value.rs b/src/lazy/binary/encoded_value.rs index f2112c49..ba3ce24d 100644 --- a/src/lazy/binary/encoded_value.rs +++ b/src/lazy/binary/encoded_value.rs @@ -222,8 +222,8 @@ impl EncodedValue { /// complete encoding, not including any annotations. pub fn unannotated_value_range(&self) -> Range { // [ annotations? | header (type descriptor) | header_length? | value ] - let start = self.header_offset - self.annotations_header_length as usize; - let end = start + self.total_length; + let start = self.header_offset; + let end = start + self.total_length - self.annotations_header_length as usize; start..end } diff --git a/src/lazy/binary/immutable_buffer.rs b/src/lazy/binary/immutable_buffer.rs index 1d950aae..6db71279 100644 --- a/src/lazy/binary/immutable_buffer.rs +++ b/src/lazy/binary/immutable_buffer.rs @@ -429,6 +429,12 @@ impl<'a> ImmutableBuffer<'a> { // Skip over the annotations sequence itself; the reader will return to it if/when the // reader asks to iterate over those symbol IDs. + if input_after_annotations_length.len() < annotations_length.value() { + return IonResult::incomplete( + "an annotations sequence", + input_after_annotations_length.offset(), + ); + } let final_input = input_after_annotations_length.consume(annotations_length.value()); // Here, `self` is the (immutable) buffer we started with. Comparing it with `input` diff --git a/src/lazy/binary/raw/reader.rs b/src/lazy/binary/raw/reader.rs index 13c40bf6..173ab6e1 100644 --- a/src/lazy/binary/raw/reader.rs +++ b/src/lazy/binary/raw/reader.rs @@ -2,9 +2,7 @@ use crate::lazy::binary::immutable_buffer::ImmutableBuffer; use crate::lazy::binary::raw::value::LazyRawBinaryValue_1_0; -use crate::lazy::decoder::{ - HasRange, LazyDecoder, LazyRawFieldExpr, LazyRawReader, RawVersionMarker, -}; +use crate::lazy::decoder::{Decoder, HasRange, LazyRawFieldExpr, LazyRawReader, RawVersionMarker}; use crate::lazy::encoding::BinaryEncoding_1_0; use crate::lazy::raw_stream_item::{EndPosition, LazyRawStreamItem, RawStreamItem}; use crate::result::IonFailure; @@ -114,7 +112,7 @@ impl<'data> LazyRawReader<'data, BinaryEncoding_1_0> for LazyRawBinaryReader_1_0 fn resume_at_offset( data: &'data [u8], offset: usize, - _config: ::ReaderSavedState, + _config: ::ReaderSavedState, ) -> Self { LazyRawBinaryReader_1_0 { data: DataSource { diff --git a/src/lazy/binary/raw/sequence.rs b/src/lazy/binary/raw/sequence.rs index 1480190f..80113cb0 100644 --- a/src/lazy/binary/raw/sequence.rs +++ b/src/lazy/binary/raw/sequence.rs @@ -6,7 +6,7 @@ use crate::lazy::binary::raw::reader::DataSource; use crate::lazy::binary::raw::value::LazyRawBinaryValue_1_0; use crate::lazy::decoder::private::LazyContainerPrivate; use crate::lazy::decoder::{ - LazyDecoder, LazyRawContainer, LazyRawSequence, LazyRawValueExpr, RawValueExpr, + Decoder, LazyRawContainer, LazyRawSequence, LazyRawValueExpr, RawValueExpr, }; use crate::lazy::encoding::BinaryEncoding_1_0; use crate::{IonResult, IonType}; @@ -37,7 +37,7 @@ impl<'top> LazyContainerPrivate<'top, BinaryEncoding_1_0> for LazyRawBinaryList_ } impl<'top> LazyRawContainer<'top, BinaryEncoding_1_0> for LazyRawBinaryList_1_0<'top> { - fn as_value(&self) -> ::Value<'top> { + fn as_value(&self) -> ::Value<'top> { self.sequence.value } } @@ -67,7 +67,7 @@ impl<'top> LazyContainerPrivate<'top, BinaryEncoding_1_0> for LazyRawBinarySExp_ } impl<'top> LazyRawContainer<'top, BinaryEncoding_1_0> for LazyRawBinarySExp_1_0<'top> { - fn as_value(&self) -> ::Value<'top> { + fn as_value(&self) -> ::Value<'top> { self.sequence.value } } diff --git a/src/lazy/binary/raw/struct.rs b/src/lazy/binary/raw/struct.rs index 91578c22..e7f8a31d 100644 --- a/src/lazy/binary/raw/struct.rs +++ b/src/lazy/binary/raw/struct.rs @@ -10,8 +10,7 @@ use crate::lazy::binary::raw::reader::DataSource; use crate::lazy::binary::raw::value::LazyRawBinaryValue_1_0; use crate::lazy::decoder::private::LazyContainerPrivate; use crate::lazy::decoder::{ - HasRange, HasSpan, LazyDecoder, LazyRawContainer, LazyRawFieldExpr, LazyRawFieldName, - LazyRawStruct, + Decoder, HasRange, HasSpan, LazyRawContainer, LazyRawFieldExpr, LazyRawFieldName, LazyRawStruct, }; use crate::lazy::encoding::BinaryEncoding_1_0; use crate::lazy::span::Span; @@ -70,7 +69,7 @@ impl<'top> LazyContainerPrivate<'top, BinaryEncoding_1_0> for LazyRawBinaryStruc } impl<'top> LazyRawContainer<'top, BinaryEncoding_1_0> for LazyRawBinaryStruct_1_0<'top> { - fn as_value(&self) -> ::Value<'top> { + fn as_value(&self) -> ::Value<'top> { self.value } } diff --git a/src/lazy/binary/raw/v1_1/reader.rs b/src/lazy/binary/raw/v1_1/reader.rs index 9cf5dda9..6e939789 100644 --- a/src/lazy/binary/raw/v1_1/reader.rs +++ b/src/lazy/binary/raw/v1_1/reader.rs @@ -2,7 +2,7 @@ use crate::lazy::binary::raw::v1_1::immutable_buffer::ImmutableBuffer; use crate::lazy::binary::raw::v1_1::value::LazyRawBinaryValue_1_1; -use crate::lazy::decoder::{LazyDecoder, LazyRawReader, RawVersionMarker}; +use crate::lazy::decoder::{Decoder, LazyRawReader, RawVersionMarker}; use crate::lazy::encoder::private::Sealed; use crate::lazy::encoding::BinaryEncoding_1_1; use crate::lazy::raw_stream_item::{EndPosition, LazyRawStreamItem, RawStreamItem}; @@ -156,7 +156,7 @@ impl<'data> LazyRawReader<'data, BinaryEncoding_1_1> for LazyRawBinaryReader_1_1 fn resume_at_offset( data: &'data [u8], offset: usize, - _saved_state: ::ReaderSavedState, + _saved_state: ::ReaderSavedState, ) -> Self { Self::new_with_offset(data, offset) } diff --git a/src/lazy/binary/raw/v1_1/sequence.rs b/src/lazy/binary/raw/v1_1/sequence.rs index c2b98ad2..df4bead1 100644 --- a/src/lazy/binary/raw/v1_1/sequence.rs +++ b/src/lazy/binary/raw/v1_1/sequence.rs @@ -5,7 +5,7 @@ use crate::lazy::binary::raw::v1_1::immutable_buffer::ImmutableBuffer; use crate::lazy::binary::raw::v1_1::value::LazyRawBinaryValue_1_1; use crate::lazy::decoder::private::LazyContainerPrivate; use crate::lazy::decoder::{ - LazyDecoder, LazyRawContainer, LazyRawSequence, LazyRawValueExpr, RawValueExpr, + Decoder, LazyRawContainer, LazyRawSequence, LazyRawValueExpr, RawValueExpr, }; use crate::lazy::encoding::BinaryEncoding_1_1; use crate::{IonResult, IonType}; @@ -30,7 +30,7 @@ impl<'top> LazyContainerPrivate<'top, BinaryEncoding_1_1> for LazyRawBinaryList_ } impl<'top> LazyRawContainer<'top, BinaryEncoding_1_1> for LazyRawBinaryList_1_1<'top> { - fn as_value(&self) -> ::Value<'top> { + fn as_value(&self) -> ::Value<'top> { self.sequence.value } } @@ -60,7 +60,7 @@ impl<'top> LazyContainerPrivate<'top, BinaryEncoding_1_1> for LazyRawBinarySExp_ } impl<'top> LazyRawContainer<'top, BinaryEncoding_1_1> for LazyRawBinarySExp_1_1<'top> { - fn as_value(&self) -> ::Value<'top> { + fn as_value(&self) -> ::Value<'top> { self.sequence.value } } diff --git a/src/lazy/binary/raw/v1_1/struct.rs b/src/lazy/binary/raw/v1_1/struct.rs index e6963152..3147d6b6 100644 --- a/src/lazy/binary/raw/v1_1/struct.rs +++ b/src/lazy/binary/raw/v1_1/struct.rs @@ -10,8 +10,7 @@ use crate::lazy::binary::raw::v1_1::{ }; use crate::lazy::decoder::private::LazyContainerPrivate; use crate::lazy::decoder::{ - HasRange, HasSpan, LazyDecoder, LazyRawContainer, LazyRawFieldExpr, LazyRawFieldName, - LazyRawStruct, + Decoder, HasRange, HasSpan, LazyRawContainer, LazyRawFieldExpr, LazyRawFieldName, LazyRawStruct, }; use crate::lazy::encoding::BinaryEncoding_1_1; use crate::lazy::span::Span; @@ -100,7 +99,7 @@ impl<'top> LazyContainerPrivate<'top, BinaryEncoding_1_1> for LazyRawBinaryStruc } impl<'top> LazyRawContainer<'top, BinaryEncoding_1_1> for LazyRawBinaryStruct_1_1<'top> { - fn as_value(&self) -> ::Value<'top> { + fn as_value(&self) -> ::Value<'top> { self.value } } diff --git a/src/lazy/binary/raw/v1_1/value.rs b/src/lazy/binary/raw/v1_1/value.rs index 316b36dc..1b38304d 100644 --- a/src/lazy/binary/raw/v1_1/value.rs +++ b/src/lazy/binary/raw/v1_1/value.rs @@ -16,7 +16,7 @@ use crate::{ value::ValueParseResult, }, }, - decoder::{LazyDecoder, LazyRawValue}, + decoder::{Decoder, LazyRawValue}, encoder::binary::v1_1::fixed_int::FixedInt, encoding::BinaryEncoding_1_1, raw_value_ref::RawValueRef, @@ -91,7 +91,7 @@ impl<'top> LazyRawValue<'top, BinaryEncoding_1_1> for LazyRawBinaryValue_1_1<'to self.is_null() } - fn annotations(&self) -> ::AnnotationsIterator<'top> { + fn annotations(&self) -> ::AnnotationsIterator<'top> { self.annotations() } diff --git a/src/lazy/binary/test_utilities.rs b/src/lazy/binary/test_utilities.rs index ad21a3c1..27023218 100644 --- a/src/lazy/binary/test_utilities.rs +++ b/src/lazy/binary/test_utilities.rs @@ -1,5 +1,5 @@ use crate::element::Element; -use crate::lazy::encoder::writer::IonWriter; +use crate::lazy::encoder::writer::Writer; use crate::lazy::encoding::BinaryEncoding_1_0; use crate::write_config::WriteConfig; use crate::IonResult; @@ -8,7 +8,7 @@ use crate::IonResult; pub fn to_binary_ion(text_ion: &str) -> IonResult> { let buffer = Vec::new(); let config = WriteConfig::::new(); - let mut writer = IonWriter::with_config(config, buffer)?; + let mut writer = Writer::with_config(config, buffer)?; let elements = Element::read_all(text_ion)?; for element in &elements { writer.write(element)?; diff --git a/src/lazy/decoder.rs b/src/lazy/decoder.rs index 6b2acb7c..5cafc3a1 100644 --- a/src/lazy/decoder.rs +++ b/src/lazy/decoder.rs @@ -26,7 +26,7 @@ pub trait HasRange { // However, many types are generic over some `D: LazyDecoder`, and having this trait // extend 'static, Sized, Debug, Clone and Copy means that those types can #[derive(...)] // those traits themselves without boilerplate `where` clauses. -pub trait LazyDecoder: 'static + Sized + Debug + Clone + Copy { +pub trait Decoder: 'static + Sized + Debug + Clone + Copy { /// A lazy reader that yields [`Self::Value`]s representing the top level values in its input. type Reader<'data>: LazyRawReader<'data, Self>; /// Additional data (beyond the offset) that the reader will need in order to resume reading @@ -91,7 +91,7 @@ pub enum RawValueExpr { /// For a version of this type that is not constrained to a particular encoding, see /// [`RawValueExpr`]. pub type LazyRawValueExpr<'top, D> = - RawValueExpr<::Value<'top>, ::EExp<'top>>; + RawValueExpr<::Value<'top>, ::EExp<'top>>; impl RawValueExpr { pub fn expect_value(self) -> IonResult { @@ -137,13 +137,13 @@ impl<'top, V: HasSpan<'top>, M: HasSpan<'top>> HasSpan<'top> for RawValueExpr { +pub enum LazyRawFieldExpr<'top, D: Decoder> { NameValue(D::FieldName<'top>, D::Value<'top>), NameEExp(D::FieldName<'top>, D::EExp<'top>), EExp(D::EExp<'top>), } -impl<'top, D: LazyDecoder> LazyRawFieldExpr<'top, D> { +impl<'top, D: Decoder> LazyRawFieldExpr<'top, D> { pub fn expect_name_value(self) -> IonResult<(D::FieldName<'top>, D::Value<'top>)> { let LazyRawFieldExpr::NameValue(name, value) = self else { return IonResult::decoding_error(format!( @@ -178,7 +178,7 @@ impl<'top, D: LazyDecoder> LazyRawFieldExpr<'top, D> { // ======= 1.0 text fields are guaranteed to have a name and value ====== impl<'top> LazyRawFieldExpr<'top, TextEncoding_1_0> { - pub fn name(&self) -> ::FieldName<'top> { + pub fn name(&self) -> ::FieldName<'top> { use LazyRawFieldExpr::*; match self { NameValue(name, _value) => *name, @@ -186,7 +186,7 @@ impl<'top> LazyRawFieldExpr<'top, TextEncoding_1_0> { EExp(_) => unreachable!("eexp field in text Ion 1.0"), } } - pub fn value(&self) -> ::Value<'top> { + pub fn value(&self) -> ::Value<'top> { use LazyRawFieldExpr::*; match self { NameValue(_name, value) => *value, @@ -198,8 +198,8 @@ impl<'top> LazyRawFieldExpr<'top, TextEncoding_1_0> { pub fn name_and_value( &self, ) -> ( - ::FieldName<'top>, - ::Value<'top>, + ::FieldName<'top>, + ::Value<'top>, ) { use LazyRawFieldExpr::*; match self { @@ -213,7 +213,7 @@ impl<'top> LazyRawFieldExpr<'top, TextEncoding_1_0> { // ======= 1.0 binary fields are guaranteed to have a name and value ====== impl<'top> LazyRawFieldExpr<'top, BinaryEncoding_1_0> { - pub fn name(&self) -> ::FieldName<'top> { + pub fn name(&self) -> ::FieldName<'top> { use LazyRawFieldExpr::*; match self { NameValue(name, _value) => *name, @@ -221,7 +221,7 @@ impl<'top> LazyRawFieldExpr<'top, BinaryEncoding_1_0> { EExp(_) => unreachable!("eexp field in text Ion 1.0"), } } - pub fn value(&self) -> ::Value<'top> { + pub fn value(&self) -> ::Value<'top> { use LazyRawFieldExpr::*; match self { NameValue(_name, value) => *value, @@ -233,8 +233,8 @@ impl<'top> LazyRawFieldExpr<'top, BinaryEncoding_1_0> { pub fn name_and_value( &self, ) -> ( - ::FieldName<'top>, - ::Value<'top>, + ::FieldName<'top>, + ::Value<'top>, ) { use LazyRawFieldExpr::*; match self { @@ -245,7 +245,7 @@ impl<'top> LazyRawFieldExpr<'top, BinaryEncoding_1_0> { } } -impl<'top, D: LazyDecoder> HasRange for LazyRawFieldExpr<'top, D> { +impl<'top, D: Decoder> HasRange for LazyRawFieldExpr<'top, D> { // This type does not offer a `span()` method to get the bytes of the entire field. // In the case of a name/value or name/eexp pair, text parsers would need to provide a span that // included the interstitial whitespace and delimiting `:` between the name and value, @@ -272,15 +272,15 @@ pub(crate) mod private { use crate::lazy::expanded::EncodingContextRef; use crate::IonResult; - use super::{LazyDecoder, LazyRawFieldExpr, LazyRawStruct}; + use super::{Decoder, LazyRawFieldExpr, LazyRawStruct}; - pub trait LazyContainerPrivate<'top, D: LazyDecoder> { + pub trait LazyContainerPrivate<'top, D: Decoder> { /// Constructs a new lazy raw container from a lazy raw value that has been confirmed to be /// of the correct type. fn from_value(value: D::Value<'top>) -> Self; } - pub trait LazyRawStructPrivate<'top, D: LazyDecoder> { + pub trait LazyRawStructPrivate<'top, D: Decoder> { /// Creates an iterator that converts each raw struct field into an `UnexpandedField`, a /// common representation for both raw fields and template fields that is used in the /// expansion process. @@ -290,18 +290,18 @@ pub(crate) mod private { ) -> RawStructUnexpandedFieldsIterator<'top, D>; } - pub struct RawStructUnexpandedFieldsIterator<'top, D: LazyDecoder> { + pub struct RawStructUnexpandedFieldsIterator<'top, D: Decoder> { context: EncodingContextRef<'top>, raw_fields: as LazyRawStruct<'top, D>>::Iterator, } - impl<'top, D: LazyDecoder> RawStructUnexpandedFieldsIterator<'top, D> { + impl<'top, D: Decoder> RawStructUnexpandedFieldsIterator<'top, D> { pub fn context(&self) -> EncodingContextRef<'top> { self.context } } - impl<'top, D: LazyDecoder> Iterator for RawStructUnexpandedFieldsIterator<'top, D> { + impl<'top, D: Decoder> Iterator for RawStructUnexpandedFieldsIterator<'top, D> { type Item = IonResult>; fn next(&mut self) -> Option { @@ -320,7 +320,7 @@ pub(crate) mod private { } } - impl<'top, D: LazyDecoder = S>, S> LazyRawStructPrivate<'top, D> for S + impl<'top, D: Decoder = S>, S> LazyRawStructPrivate<'top, D> for S where S: LazyRawStruct<'top, D>, { @@ -337,7 +337,7 @@ pub(crate) mod private { } } -pub trait LazyRawReader<'data, D: LazyDecoder>: Sized { +pub trait LazyRawReader<'data, D: Decoder>: Sized { fn new(data: &'data [u8]) -> Self { Self::resume_at_offset(data, 0, D::ReaderSavedState::default()) } @@ -361,11 +361,11 @@ pub trait LazyRawReader<'data, D: LazyDecoder>: Sized { fn position(&self) -> usize; } -pub trait LazyRawContainer<'top, D: LazyDecoder> { +pub trait LazyRawContainer<'top, D: Decoder> { fn as_value(&self) -> D::Value<'top>; } -pub trait LazyRawValue<'top, D: LazyDecoder>: +pub trait LazyRawValue<'top, D: Decoder>: HasSpan<'top> + RawValueLiteral + Copy + Clone + Debug + Sized { fn ion_type(&self) -> IonType; @@ -374,7 +374,7 @@ pub trait LazyRawValue<'top, D: LazyDecoder>: fn read(&self) -> IonResult>; } -pub trait LazyRawSequence<'top, D: LazyDecoder>: +pub trait LazyRawSequence<'top, D: Decoder>: LazyRawContainer<'top, D> + private::LazyContainerPrivate<'top, D> + Debug + Copy + Clone { type Iterator: Iterator>>; @@ -383,7 +383,7 @@ pub trait LazyRawSequence<'top, D: LazyDecoder>: fn iter(&self) -> Self::Iterator; } -pub trait LazyRawStruct<'top, D: LazyDecoder>: +pub trait LazyRawStruct<'top, D: Decoder>: LazyRawContainer<'top, D> + private::LazyContainerPrivate<'top, D> + private::LazyRawStructPrivate<'top, D> diff --git a/src/lazy/encoder/binary/v1_0/mod.rs b/src/lazy/encoder/binary/v1_0/mod.rs index ca934d78..e866e1d4 100644 --- a/src/lazy/encoder/binary/v1_0/mod.rs +++ b/src/lazy/encoder/binary/v1_0/mod.rs @@ -1,5 +1,5 @@ use crate::lazy::encoder::binary::v1_0::writer::LazyRawBinaryWriter_1_0; -use crate::lazy::encoder::{LazyEncoder, SymbolCreationPolicy}; +use crate::lazy::encoder::{Encoder, SymbolCreationPolicy}; use crate::lazy::encoding::BinaryEncoding_1_0; use std::io::Write; @@ -7,7 +7,7 @@ mod container_writers; pub mod value_writer; pub mod writer; -impl LazyEncoder for BinaryEncoding_1_0 { +impl Encoder for BinaryEncoding_1_0 { const SUPPORTS_TEXT_TOKENS: bool = false; const DEFAULT_SYMBOL_CREATION_POLICY: SymbolCreationPolicy = SymbolCreationPolicy::RequireSymbolId; diff --git a/src/lazy/encoder/binary/v1_1/mod.rs b/src/lazy/encoder/binary/v1_1/mod.rs index 5c5a3a6f..1e96ce52 100644 --- a/src/lazy/encoder/binary/v1_1/mod.rs +++ b/src/lazy/encoder/binary/v1_1/mod.rs @@ -1,7 +1,7 @@ use std::io::Write; use crate::lazy::encoder::binary::v1_1::writer::LazyRawBinaryWriter_1_1; -use crate::lazy::encoder::{LazyEncoder, SymbolCreationPolicy}; +use crate::lazy::encoder::{Encoder, SymbolCreationPolicy}; use crate::lazy::encoding::BinaryEncoding_1_1; pub mod container_writers; @@ -13,7 +13,7 @@ pub mod flex_uint; pub mod value_writer; pub mod writer; -impl LazyEncoder for BinaryEncoding_1_1 { +impl Encoder for BinaryEncoding_1_1 { const SUPPORTS_TEXT_TOKENS: bool = true; const DEFAULT_SYMBOL_CREATION_POLICY: SymbolCreationPolicy = SymbolCreationPolicy::RequireSymbolId; diff --git a/src/lazy/encoder/mod.rs b/src/lazy/encoder/mod.rs index ebedddc3..b908e82a 100644 --- a/src/lazy/encoder/mod.rs +++ b/src/lazy/encoder/mod.rs @@ -24,10 +24,7 @@ pub mod writer; // However, many types are generic over some `E: LazyEncoder`, and having this trait // extend 'static, Sized, Debug, Clone and Copy means that those types can #[derive(...)] // those traits themselves without boilerplate `where` clauses. -pub trait LazyEncoder: 'static + Sized + Debug + Clone + Copy { - // XXX: ^-- This is named 'Lazy' for symmetry with the `LazyDecoder`. In reality, there's nothing - // lazy about it. We should revisit the Lazy* naming scheme, as eventually it will be the - // only implementation of a reader and won't need the word 'Lazy' to distinguish itself. +pub trait Encoder: 'static + Sized + Debug + Clone + Copy { const SUPPORTS_TEXT_TOKENS: bool; const DEFAULT_SYMBOL_CREATION_POLICY: SymbolCreationPolicy; diff --git a/src/lazy/encoder/text/v1_0/mod.rs b/src/lazy/encoder/text/v1_0/mod.rs index 37d555aa..79a7355e 100644 --- a/src/lazy/encoder/text/v1_0/mod.rs +++ b/src/lazy/encoder/text/v1_0/mod.rs @@ -1,13 +1,13 @@ use std::io::Write; use crate::lazy::encoder::text::v1_0::writer::LazyRawTextWriter_1_0; -use crate::lazy::encoder::{LazyEncoder, SymbolCreationPolicy}; +use crate::lazy::encoder::{Encoder, SymbolCreationPolicy}; use crate::lazy::encoding::TextEncoding_1_0; pub mod value_writer; pub mod writer; -impl LazyEncoder for TextEncoding_1_0 { +impl Encoder for TextEncoding_1_0 { const SUPPORTS_TEXT_TOKENS: bool = true; const DEFAULT_SYMBOL_CREATION_POLICY: SymbolCreationPolicy = SymbolCreationPolicy::WriteProvidedToken; diff --git a/src/lazy/encoder/text/v1_1/mod.rs b/src/lazy/encoder/text/v1_1/mod.rs index 7bd7876f..444912c5 100644 --- a/src/lazy/encoder/text/v1_1/mod.rs +++ b/src/lazy/encoder/text/v1_1/mod.rs @@ -2,11 +2,11 @@ pub(crate) mod value_writer; pub(crate) mod writer; use crate::lazy::encoder::text::v1_1::writer::LazyRawTextWriter_1_1; -use crate::lazy::encoder::{LazyEncoder, SymbolCreationPolicy}; +use crate::lazy::encoder::{Encoder, SymbolCreationPolicy}; use crate::lazy::encoding::TextEncoding_1_1; use std::io::Write; -impl LazyEncoder for TextEncoding_1_1 { +impl Encoder for TextEncoding_1_1 { const SUPPORTS_TEXT_TOKENS: bool = true; const DEFAULT_SYMBOL_CREATION_POLICY: SymbolCreationPolicy = SymbolCreationPolicy::WriteProvidedToken; diff --git a/src/lazy/encoder/write_as_ion.rs b/src/lazy/encoder/write_as_ion.rs index e8be6252..fc6150b0 100644 --- a/src/lazy/encoder/write_as_ion.rs +++ b/src/lazy/encoder/write_as_ion.rs @@ -17,7 +17,7 @@ use std::io; use std::marker::PhantomData; -use crate::lazy::decoder::LazyDecoder; +use crate::lazy::decoder::Decoder; use crate::lazy::encoder::annotation_seq::AnnotationsVec; use crate::lazy::encoder::value_writer::{SequenceWriter, StructWriter, ValueWriter}; use crate::lazy::encoding::Encoding; @@ -271,7 +271,7 @@ impl WriteAsIon for Value { } } -impl<'a, D: LazyDecoder> WriteAsIon for LazyValue<'a, D> { +impl<'a, D: Decoder> WriteAsIon for LazyValue<'a, D> { fn write_as_ion(&self, writer: V) -> IonResult<()> { let mut annotations = AnnotationsVec::new(); for annotation in self.annotations() { @@ -282,7 +282,7 @@ impl<'a, D: LazyDecoder> WriteAsIon for LazyValue<'a, D> { } } -impl<'a, D: LazyDecoder> WriteAsIon for ValueRef<'a, D> { +impl<'a, D: Decoder> WriteAsIon for ValueRef<'a, D> { fn write_as_ion(&self, value_writer: V) -> IonResult<()> { use ValueRef::*; match self { diff --git a/src/lazy/encoder/writer.rs b/src/lazy/encoder/writer.rs index e3b9c1f2..dd6f284b 100644 --- a/src/lazy/encoder/writer.rs +++ b/src/lazy/encoder/writer.rs @@ -4,7 +4,6 @@ use delegate::delegate; use ice_code::ice as cold_path; use crate::constants::v1_0::system_symbol_ids; -use crate::lazy::any_encoding::AnyEncoding; use crate::lazy::encoder::annotation_seq::AnnotationSeq; use crate::lazy::encoder::value_writer::internal::{FieldEncoder, MakeValueWriter}; use crate::lazy::encoder::value_writer::{ @@ -47,20 +46,19 @@ impl EncodingContext { } /// An Ion writer that maintains a symbol table and creates new entries as needed. -pub struct IonWriter { +pub struct Writer { encoding_context: EncodingContext, data_writer: E::Writer>, directive_writer: E::Writer>, output: Output, } -pub type Writer = IonWriter; -pub type TextWriter_1_0 = IonWriter; -pub type BinaryWriter_1_0 = IonWriter; -pub type TextWriter_1_1 = IonWriter; -pub type BinaryWriter_1_1 = IonWriter; +pub type TextWriter_1_0 = Writer; +pub type BinaryWriter_1_0 = Writer; +pub type TextWriter_1_1 = Writer; +pub type BinaryWriter_1_1 = Writer; -impl IonWriter { +impl Writer { /// Constructs a writer for the requested encoding using its default configuration. pub fn new(output: Output) -> IonResult { Self::with_config(E::default_write_config(), output) @@ -79,7 +77,7 @@ impl IonWriter { E::DEFAULT_SYMBOL_CREATION_POLICY, E::SUPPORTS_TEXT_TOKENS, ); - let mut writer = IonWriter { + let mut writer = Writer { encoding_context, data_writer, directive_writer, @@ -162,7 +160,7 @@ impl IonWriter { } } -impl MakeValueWriter for IonWriter { +impl MakeValueWriter for Writer { type ValueWriter<'a> = ApplicationValueWriter<'a, > as MakeValueWriter>::ValueWriter<'a>> where Self: 'a; @@ -177,7 +175,7 @@ impl MakeValueWriter for IonWriter { } } -impl SequenceWriter for IonWriter { +impl SequenceWriter for Writer { type Resources = Output; fn close(mut self) -> IonResult { diff --git a/src/lazy/encoding.rs b/src/lazy/encoding.rs index 14bb0512..55448f1e 100644 --- a/src/lazy/encoding.rs +++ b/src/lazy/encoding.rs @@ -18,9 +18,9 @@ use crate::lazy::binary::raw::v1_1::{ RawBinaryAnnotationsIterator_1_1, }; use crate::lazy::binary::raw::value::{LazyRawBinaryValue_1_0, LazyRawBinaryVersionMarker_1_0}; -use crate::lazy::decoder::LazyDecoder; +use crate::lazy::decoder::Decoder; use crate::lazy::encoder::write_as_ion::WriteAsIon; -use crate::lazy::encoder::LazyEncoder; +use crate::lazy::encoder::Encoder; use crate::lazy::never::Never; use crate::lazy::text::raw::r#struct::{LazyRawTextFieldName_1_0, LazyRawTextStruct_1_0}; use crate::lazy::text::raw::reader::LazyRawTextReader_1_0; @@ -37,7 +37,7 @@ use crate::lazy::text::value::{ use crate::{IonResult, TextFormat, WriteConfig}; /// Marker trait for types that represent an Ion encoding. -pub trait Encoding: LazyEncoder + LazyDecoder { +pub trait Encoding: Encoder + Decoder { type Output: 'static + OutputFromBytes + AsRef<[u8]>; fn encode(value: V) -> IonResult { @@ -101,7 +101,7 @@ impl<'top> BinaryEncoding<'top> for BinaryEncoding_1_1 {} pub struct TextEncoding_1_0; impl TextEncoding_1_0 { - fn with_format(self, format: TextFormat) -> WriteConfig { + pub fn with_format(self, format: TextFormat) -> WriteConfig { WriteConfig::::new(format) } } @@ -111,7 +111,7 @@ impl TextEncoding_1_0 { pub struct TextEncoding_1_1; impl TextEncoding_1_1 { - fn with_format(self, format: TextFormat) -> WriteConfig { + pub fn with_format(self, format: TextFormat) -> WriteConfig { WriteConfig::::new(format) } } @@ -156,12 +156,12 @@ impl Encoding for TextEncoding_1_1 { } /// Marker trait for binary encodings of any version. -pub trait BinaryEncoding<'top>: Encoding> + LazyDecoder {} +pub trait BinaryEncoding<'top>: Encoding> + Decoder {} /// Marker trait for text encodings. pub trait TextEncoding<'top>: Encoding - + LazyDecoder< + + Decoder< AnnotationsIterator<'top> = RawTextAnnotationsIterator<'top>, Value<'top> = LazyRawTextValue<'top, Self>, > @@ -175,7 +175,7 @@ impl<'top> TextEncoding<'top> for TextEncoding_1_1 {} pub trait EncodingWithMacroSupport {} impl EncodingWithMacroSupport for TextEncoding_1_1 {} -impl LazyDecoder for BinaryEncoding_1_0 { +impl Decoder for BinaryEncoding_1_0 { type Reader<'data> = LazyRawBinaryReader_1_0<'data>; type ReaderSavedState = (); type Value<'top> = LazyRawBinaryValue_1_0<'top>; @@ -189,7 +189,7 @@ impl LazyDecoder for BinaryEncoding_1_0 { type VersionMarker<'top> = LazyRawBinaryVersionMarker_1_0<'top>; } -impl LazyDecoder for TextEncoding_1_0 { +impl Decoder for TextEncoding_1_0 { type Reader<'data> = LazyRawTextReader_1_0<'data>; type ReaderSavedState = (); type Value<'top> = LazyRawTextValue_1_0<'top>; @@ -203,7 +203,7 @@ impl LazyDecoder for TextEncoding_1_0 { type VersionMarker<'top> = LazyRawTextVersionMarker_1_0<'top>; } -impl LazyDecoder for TextEncoding_1_1 { +impl Decoder for TextEncoding_1_1 { type Reader<'data> = LazyRawTextReader_1_1<'data>; type ReaderSavedState = (); type Value<'top> = LazyRawTextValue_1_1<'top>; @@ -216,7 +216,7 @@ impl LazyDecoder for TextEncoding_1_1 { type VersionMarker<'top> = LazyRawTextVersionMarker_1_1<'top>; } -impl LazyDecoder for BinaryEncoding_1_1 { +impl Decoder for BinaryEncoding_1_1 { type Reader<'data> = LazyRawBinaryReader_1_1<'data>; type ReaderSavedState = (); type Value<'top> = LazyRawBinaryValue_1_1<'top>; diff --git a/src/lazy/expanded/compiler.rs b/src/lazy/expanded/compiler.rs index c8c99b07..a1787cf9 100644 --- a/src/lazy/expanded/compiler.rs +++ b/src/lazy/expanded/compiler.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use std::ops::Range; -use crate::lazy::decoder::LazyDecoder; +use crate::lazy::decoder::Decoder; use crate::lazy::expanded::template::{ ExprRange, MacroSignature, Parameter, ParameterEncoding, TemplateBody, TemplateBodyElement, TemplateBodyMacroInvocation, TemplateBodyValueExpr, TemplateMacro, TemplateStructIndex, @@ -136,7 +136,7 @@ impl TemplateCompiler { /// [`TemplateBodyValueExpr`] sequences to the `TemplateBody`. /// /// If `is_quoted` is true, nested symbols and s-expressions will not be interpreted. - fn compile_value<'top, D: LazyDecoder>( + fn compile_value<'top, D: Decoder>( context: EncodingContextRef<'top>, signature: &MacroSignature, definition: &mut TemplateBody, @@ -209,7 +209,7 @@ impl TemplateCompiler { } /// Helper method for visiting all of the child expressions in a list. - fn compile_list<'top, D: LazyDecoder>( + fn compile_list<'top, D: Decoder>( context: EncodingContextRef<'top>, signature: &MacroSignature, definition: &mut TemplateBody, @@ -237,7 +237,7 @@ impl TemplateCompiler { } /// Helper method for visiting all of the child expressions in a sexp. - fn compile_sexp<'top, D: LazyDecoder>( + fn compile_sexp<'top, D: Decoder>( context: EncodingContextRef<'top>, signature: &MacroSignature, definition: &mut TemplateBody, @@ -271,7 +271,7 @@ impl TemplateCompiler { /// Adds a `lazy_sexp` that has been determined to represent a macro invocation to the /// TemplateBody. - fn compile_macro<'top, D: LazyDecoder>( + fn compile_macro<'top, D: Decoder>( context: EncodingContextRef<'top>, signature: &MacroSignature, definition: &mut TemplateBody, @@ -310,7 +310,7 @@ impl TemplateCompiler { /// Given a `LazyValue` that represents a macro ID (name or address), attempts to resolve the /// ID to a macro address. - fn name_and_address_from_id_expr<'top, D: LazyDecoder>( + fn name_and_address_from_id_expr<'top, D: Decoder>( context: EncodingContextRef<'top>, id_expr: Option>>, ) -> IonResult<(Option, usize)> { @@ -351,7 +351,7 @@ impl TemplateCompiler { /// Visits all of the child expressions of `lazy_sexp`, adding them to the `TemplateBody` /// without interpretation. `lazy_sexp` itself is the `quote` macro, and does not get added /// to the template body as there is nothing more for it to do at evaluation time. - fn compile_quoted_elements<'top, D: LazyDecoder>( + fn compile_quoted_elements<'top, D: Decoder>( context: EncodingContextRef<'top>, signature: &MacroSignature, definition: &mut TemplateBody, @@ -374,7 +374,7 @@ impl TemplateCompiler { } /// Adds `lazy_sexp` to the template body without interpretation. - fn compile_quoted_sexp<'top, D: LazyDecoder>( + fn compile_quoted_sexp<'top, D: Decoder>( context: EncodingContextRef<'top>, signature: &MacroSignature, definition: &mut TemplateBody, @@ -404,7 +404,7 @@ impl TemplateCompiler { /// Returns `Ok(true)` if the first child value in the `LazySexp` is the symbol `quote`. /// This method should only be called in an unquoted context. - fn sexp_is_quote_macro(sexp: &LazySExp) -> IonResult { + fn sexp_is_quote_macro(sexp: &LazySExp) -> IonResult { let first_expr = sexp.iter().next(); match first_expr { // If the sexp is empty and we're not in a quoted context, that's an error. @@ -418,7 +418,7 @@ impl TemplateCompiler { } /// Recursively adds all of the expressions in `lazy_struct` to the `TemplateBody`. - fn compile_struct<'top, D: LazyDecoder>( + fn compile_struct<'top, D: Decoder>( context: EncodingContextRef<'top>, signature: &MacroSignature, definition: &mut TemplateBody, diff --git a/src/lazy/expanded/e_expression.rs b/src/lazy/expanded/e_expression.rs index 0ef6c1c9..0bc4bdd2 100644 --- a/src/lazy/expanded/e_expression.rs +++ b/src/lazy/expanded/e_expression.rs @@ -1,7 +1,7 @@ //! Types and traits representing an e-expression in an Ion stream. #![allow(non_camel_case_types)] -use crate::lazy::decoder::{LazyDecoder, LazyRawValueExpr}; +use crate::lazy::decoder::{Decoder, LazyRawValueExpr}; use crate::lazy::encoding::TextEncoding_1_1; use crate::lazy::expanded::macro_evaluator::{MacroExpr, RawEExpression, ValueExpr}; use crate::lazy::expanded::macro_table::MacroRef; @@ -12,13 +12,13 @@ use std::fmt::{Debug, Formatter}; /// An e-expression (in Ion format `D`) that has been resolved in the current encoding context. #[derive(Copy, Clone)] -pub struct EExpression<'top, D: LazyDecoder> { +pub struct EExpression<'top, D: Decoder> { pub(crate) context: EncodingContextRef<'top>, pub(crate) raw_invocation: D::EExp<'top>, pub(crate) invoked_macro: MacroRef<'top>, } -impl<'top, D: LazyDecoder> EExpression<'top, D> { +impl<'top, D: Decoder> EExpression<'top, D> { pub fn context(&self) -> EncodingContextRef<'top> { self.context } @@ -30,13 +30,13 @@ impl<'top, D: LazyDecoder> EExpression<'top, D> { } } -impl<'top, D: LazyDecoder> Debug for EExpression<'top, D> { +impl<'top, D: Decoder> Debug for EExpression<'top, D> { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "EExpression {:?}", self.raw_invocation) } } -impl<'top, D: LazyDecoder> EExpression<'top, D> { +impl<'top, D: Decoder> EExpression<'top, D> { pub fn new( context: EncodingContextRef<'top>, raw_invocation: D::EExp<'top>, @@ -50,7 +50,7 @@ impl<'top, D: LazyDecoder> EExpression<'top, D> { } } -impl<'top, D: LazyDecoder> EExpression<'top, D> { +impl<'top, D: Decoder> EExpression<'top, D> { pub fn id(&self) -> MacroIdRef<'top> { self.raw_invocation.id() } @@ -63,18 +63,18 @@ impl<'top, D: LazyDecoder> EExpression<'top, D> { } } -impl<'top, D: LazyDecoder> From> for MacroExpr<'top, D> { +impl<'top, D: Decoder> From> for MacroExpr<'top, D> { fn from(value: EExpression<'top, D>) -> Self { MacroExpr::EExp(value) } } -pub struct EExpressionArgsIterator<'top, D: LazyDecoder> { +pub struct EExpressionArgsIterator<'top, D: Decoder> { context: EncodingContextRef<'top>, raw_args: as RawEExpression<'top, D>>::RawArgumentsIterator<'top>, } -impl<'top, D: LazyDecoder> Iterator for EExpressionArgsIterator<'top, D> { +impl<'top, D: Decoder> Iterator for EExpressionArgsIterator<'top, D> { type Item = IonResult>; fn next(&mut self) -> Option { diff --git a/src/lazy/expanded/macro_evaluator.rs b/src/lazy/expanded/macro_evaluator.rs index 83ada230..359c1935 100644 --- a/src/lazy/expanded/macro_evaluator.rs +++ b/src/lazy/expanded/macro_evaluator.rs @@ -16,7 +16,7 @@ use std::fmt::{Debug, Formatter}; use bumpalo::collections::{String as BumpString, Vec as BumpVec}; -use crate::lazy::decoder::{HasSpan, LazyDecoder, LazyRawValueExpr}; +use crate::lazy::decoder::{Decoder, HasSpan, LazyRawValueExpr}; use crate::lazy::expanded::e_expression::{EExpression, EExpressionArgsIterator}; use crate::lazy::expanded::macro_table::{MacroKind, MacroRef}; use crate::lazy::expanded::sequence::Environment; @@ -33,7 +33,7 @@ use crate::{IonError, IonResult, RawSymbolRef}; /// The syntactic entity in format `D` that represents an e-expression. This expression has not /// yet been resolved in the current encoding context. -pub trait RawEExpression<'top, D: LazyDecoder = Self>>: +pub trait RawEExpression<'top, D: Decoder = Self>>: HasSpan<'top> + Debug + Copy + Clone { /// An iterator that yields the macro invocation's arguments in order. @@ -66,14 +66,14 @@ pub trait RawEExpression<'top, D: LazyDecoder = Self>>: /// This invocation has been resolved in the current encoding context, and holds a reference to /// the definition of the macro being invoked. #[derive(Copy, Clone, Debug)] -pub enum MacroExpr<'top, D: LazyDecoder> { +pub enum MacroExpr<'top, D: Decoder> { /// A macro invocation found in the body of a template. TemplateMacro(TemplateMacroInvocation<'top>), /// A macro invocation found in the data stream. EExp(EExpression<'top, D>), } -impl<'top, D: LazyDecoder> MacroExpr<'top, D> { +impl<'top, D: Decoder> MacroExpr<'top, D> { fn id(&self) -> MacroIdRef { match &self { MacroExpr::TemplateMacro(m) => m.id(), @@ -106,16 +106,16 @@ impl<'top, D: LazyDecoder> MacroExpr<'top, D> { } } -pub enum MacroExprArgsKind<'top, D: LazyDecoder> { +pub enum MacroExprArgsKind<'top, D: Decoder> { Macro(TemplateMacroInvocationArgsIterator<'top, D>), EExp(EExpressionArgsIterator<'top, D>), } -pub struct MacroExprArgsIterator<'top, D: LazyDecoder> { +pub struct MacroExprArgsIterator<'top, D: Decoder> { source: MacroExprArgsKind<'top, D>, } -impl<'top, D: LazyDecoder> Iterator for MacroExprArgsIterator<'top, D> { +impl<'top, D: Decoder> Iterator for MacroExprArgsIterator<'top, D> { type Item = IonResult>; fn next(&mut self) -> Option { @@ -135,7 +135,7 @@ impl<'top, D: LazyDecoder> Iterator for MacroExprArgsIterator<'top, D> { /// A single expression appearing in argument position within a macro invocation. #[derive(Debug, Copy, Clone)] -pub enum ArgExpr<'top, D: LazyDecoder> { +pub enum ArgExpr<'top, D: Decoder> { /// An Ion value that requires no further evaluation. // `LazyExpandedValue` can be backed by either a stream value or a template value, so it covers // both contexts. @@ -147,7 +147,7 @@ pub enum ArgExpr<'top, D: LazyDecoder> { MacroInvocation(MacroExpr<'top, D>), } -impl<'top, D: LazyDecoder> ArgExpr<'top, D> { +impl<'top, D: Decoder> ArgExpr<'top, D> { /// If this `ArgExpr` is a variable reference, resolves it to an expression from its originating /// environment. Returns an `ArgValueExpr` which is the value literal or macro invocation to /// which the variable referred. @@ -169,7 +169,7 @@ impl<'top, D: LazyDecoder> ArgExpr<'top, D> { /// A `ValueExpr` is a resolved value. It cannot be a variable reference. If it is a macro /// invocation, it holds a reference to the definition of the macro it invokes. #[derive(Debug, Copy, Clone)] -pub enum ValueExpr<'top, D: LazyDecoder> { +pub enum ValueExpr<'top, D: Decoder> { /// An Ion value that requires no further evaluation. // `LazyExpandedValue` can be backed by either a stream value or a template value, so it covers // both contexts. @@ -180,7 +180,7 @@ pub enum ValueExpr<'top, D: LazyDecoder> { /// Indicates which of the supported macros this represents and stores the state necessary to /// continue evaluating that macro. -pub enum MacroExpansionKind<'top, D: LazyDecoder> { +pub enum MacroExpansionKind<'top, D: Decoder> { Void, Values(ValuesExpansion<'top, D>), MakeString(MakeStringExpansion<'top, D>), @@ -189,18 +189,18 @@ pub enum MacroExpansionKind<'top, D: LazyDecoder> { /// A macro in the process of being evaluated. Stores both the state of the evaluation and the /// syntactic element that represented the macro invocation. -pub struct MacroExpansion<'top, D: LazyDecoder> { +pub struct MacroExpansion<'top, D: Decoder> { kind: MacroExpansionKind<'top, D>, invocation: MacroExpr<'top, D>, } -impl<'top, D: LazyDecoder> MacroExpansion<'top, D> { +impl<'top, D: Decoder> MacroExpansion<'top, D> { pub(crate) fn new(kind: MacroExpansionKind<'top, D>, invocation: MacroExpr<'top, D>) -> Self { Self { kind, invocation } } } -impl<'top, D: LazyDecoder> Debug for MacroExpansion<'top, D> { +impl<'top, D: Decoder> Debug for MacroExpansion<'top, D> { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { let name = match &self.kind { MacroExpansionKind::Void => "void", @@ -214,7 +214,7 @@ impl<'top, D: LazyDecoder> Debug for MacroExpansion<'top, D> { } } -impl<'top, D: LazyDecoder> MacroExpansion<'top, D> { +impl<'top, D: Decoder> MacroExpansion<'top, D> { /// Continues evaluating this macro until it: /// * produces another value. /// * encounters another macro or variable that needs to be expanded. @@ -249,7 +249,7 @@ pub type EnvironmentStack<'top, D> = BumpVec<'top, Environment<'top, D>>; /// /// For eager evaluation, use [`MacroEvaluator::evaluate`], which returns an iterator that will /// yield the expanded values. -pub struct MacroEvaluator<'top, D: LazyDecoder> { +pub struct MacroEvaluator<'top, D: Decoder> { // A stack with the most recent macro invocations at the top. This stack grows each time a macro // of any kind begins evaluation. macro_stack: MacroStack<'top, D>, @@ -267,7 +267,7 @@ pub struct MacroEvaluator<'top, D: LazyDecoder> { env_stack: EnvironmentStack<'top, D>, } -impl<'top, D: LazyDecoder> MacroEvaluator<'top, D> { +impl<'top, D: Decoder> MacroEvaluator<'top, D> { pub fn new(context: EncodingContextRef<'top>, environment: Environment<'top, D>) -> Self { let macro_stack = BumpVec::new_in(context.allocator); let mut env_stack = BumpVec::new_in(context.allocator); @@ -464,12 +464,12 @@ impl<'top, D: LazyDecoder> MacroEvaluator<'top, D> { /// Yields the values produced by incrementally evaluating the macro that was at the top of the /// evaluator's stack when the iterator was created. -pub struct EvaluatingIterator<'iter, 'top, D: LazyDecoder> { +pub struct EvaluatingIterator<'iter, 'top, D: Decoder> { evaluator: &'iter mut MacroEvaluator<'top, D>, initial_stack_depth: usize, } -impl<'iter, 'top, D: LazyDecoder> EvaluatingIterator<'iter, 'top, D> { +impl<'iter, 'top, D: Decoder> EvaluatingIterator<'iter, 'top, D> { pub fn new(evaluator: &'iter mut MacroEvaluator<'top, D>) -> Self { let initial_stack_depth = evaluator.macro_stack_depth(); Self { @@ -479,7 +479,7 @@ impl<'iter, 'top, D: LazyDecoder> EvaluatingIterator<'iter, 'top, D> { } } -impl<'iter, 'top, D: LazyDecoder> Iterator for EvaluatingIterator<'iter, 'top, D> { +impl<'iter, 'top, D: Decoder> Iterator for EvaluatingIterator<'iter, 'top, D> { type Item = IonResult>; fn next(&mut self) -> Option { @@ -501,7 +501,7 @@ impl<'iter, 'top, D: LazyDecoder> Iterator for EvaluatingIterator<'iter, 'top, D /// (:values 1) => 1 /// (:values 1 2 3) => 1 2 3 /// (:values 1 2 (:values 3 4)) => 1 2 3 4 -pub struct ValuesExpansion<'top, D: LazyDecoder> { +pub struct ValuesExpansion<'top, D: Decoder> { // Which argument the macro is in the process of expanding arguments: MacroExprArgsIterator<'top, D>, // The stack depth where this `values` call lives. When the stack shrinks below this depth, @@ -509,7 +509,7 @@ pub struct ValuesExpansion<'top, D: LazyDecoder> { initial_eval_stack_depth: usize, } -impl<'top, D: LazyDecoder> ValuesExpansion<'top, D> { +impl<'top, D: Decoder> ValuesExpansion<'top, D> { pub fn new(arguments: MacroExprArgsIterator<'top, D>, initial_eval_stack_depth: usize) -> Self { Self { arguments, @@ -548,12 +548,12 @@ impl<'top, D: LazyDecoder> ValuesExpansion<'top, D> { /// (:make_string (:values "first" "_") $4) => "first_name" /// (:make_string) => "" /// (:make_string "foo" 7) => Error -pub struct MakeStringExpansion<'top, D: LazyDecoder> { +pub struct MakeStringExpansion<'top, D: Decoder> { arguments: MacroExprArgsIterator<'top, D>, is_complete: bool, } -impl<'top, D: LazyDecoder> MakeStringExpansion<'top, D> { +impl<'top, D: Decoder> MakeStringExpansion<'top, D> { pub fn new(arguments: MacroExprArgsIterator<'top, D>) -> Self { Self { arguments, @@ -665,7 +665,7 @@ impl<'top> TemplateExpansion<'top> { } } - fn next<'data: 'top, D: LazyDecoder>( + fn next<'data: 'top, D: Decoder>( &mut self, context: EncodingContextRef<'top>, environment: Environment<'top, D>, diff --git a/src/lazy/expanded/mod.rs b/src/lazy/expanded/mod.rs index da89a5eb..5e1d3c1b 100644 --- a/src/lazy/expanded/mod.rs +++ b/src/lazy/expanded/mod.rs @@ -43,7 +43,7 @@ use sequence::{LazyExpandedList, LazyExpandedSExp}; use crate::element::iterators::SymbolsIterator; use crate::lazy::bytes_ref::BytesRef; -use crate::lazy::decoder::{LazyDecoder, LazyRawValue}; +use crate::lazy::decoder::{Decoder, LazyRawValue}; use crate::lazy::encoding::RawValueLiteral; use crate::lazy::expanded::compiler::TemplateCompiler; use crate::lazy::expanded::macro_evaluator::{MacroEvaluator, RawEExpression}; @@ -134,7 +134,7 @@ impl<'top> Deref for EncodingContextRef<'top> { #[derive(Debug)] /// Stream components emitted by a LazyExpandingReader. These items may be encoded directly in the /// stream, or may have been produced by the evaluation of an encoding expression (e-expression). -pub enum ExpandedStreamItem<'top, D: LazyDecoder> { +pub enum ExpandedStreamItem<'top, D: Decoder> { /// An Ion Version Marker (IVM) indicating the Ion major and minor version that were used to /// encode the values that follow. VersionMarker(u8, u8), @@ -146,7 +146,7 @@ pub enum ExpandedStreamItem<'top, D: LazyDecoder> { EndOfStream, } -impl<'top, D: LazyDecoder> ExpandedStreamItem<'top, D> { +impl<'top, D: Decoder> ExpandedStreamItem<'top, D> { /// Returns an error if this stream item is a version marker or the end of the stream. /// Otherwise, returns the lazy value it contains. fn expect_value(&self) -> IonResult<&LazyExpandedValue<'top, D>> { @@ -159,7 +159,7 @@ impl<'top, D: LazyDecoder> ExpandedStreamItem<'top, D> { /// A reader that evaluates macro invocations in the data stream and surfaces the resulting /// raw values to the caller. -pub struct ExpandingReader { +pub struct ExpandingReader { raw_reader: UnsafeCell>, // The expanding raw reader needs to be able to return multiple values from a single expression. // For example, if the raw reader encounters this e-expression: @@ -220,7 +220,7 @@ pub struct ExpandingReader { macro_table: UnsafeCell, } -impl ExpandingReader { +impl ExpandingReader { pub(crate) fn new(raw_reader: StreamingRawReader) -> Self { Self { raw_reader: raw_reader.into(), @@ -466,7 +466,7 @@ impl ExpandingReader { /// The source of data backing a [`LazyExpandedValue`]. #[derive(Copy, Clone)] -pub enum ExpandedValueSource<'top, D: LazyDecoder> { +pub enum ExpandedValueSource<'top, D: Decoder> { /// This value was a literal in the input stream. ValueLiteral(D::Value<'top>), /// This value was part of a template definition. @@ -482,7 +482,7 @@ pub enum ExpandedValueSource<'top, D: LazyDecoder> { ), } -impl<'top, Encoding: LazyDecoder> Debug for ExpandedValueSource<'top, Encoding> { +impl<'top, Encoding: Decoder> Debug for ExpandedValueSource<'top, Encoding> { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { match &self { ExpandedValueSource::ValueLiteral(v) => write!(f, "{v:?}"), @@ -496,7 +496,7 @@ impl<'top, Encoding: LazyDecoder> Debug for ExpandedValueSource<'top, Encoding> // Converts the raw value literal types associated with each format decoder (e.g. LazyRawTextValue_1_1) // into an ExpandedValueSource. -impl<'top, V: RawValueLiteral, Encoding: LazyDecoder = V>> From +impl<'top, V: RawValueLiteral, Encoding: Decoder = V>> From for ExpandedValueSource<'top, Encoding> { fn from(value: V) -> Self { @@ -534,7 +534,7 @@ impl<'top> TemplateVariableReference<'top> { /// A value produced by expanding the 'raw' view of the input data. #[derive(Copy, Clone)] -pub struct LazyExpandedValue<'top, Encoding: LazyDecoder> { +pub struct LazyExpandedValue<'top, Encoding: Decoder> { pub(crate) context: EncodingContextRef<'top>, pub(crate) source: ExpandedValueSource<'top, Encoding>, // If this value came from a variable reference in a template macro expansion, the @@ -542,13 +542,13 @@ pub struct LazyExpandedValue<'top, Encoding: LazyDecoder> { pub(crate) variable: Option>, } -impl<'top, Encoding: LazyDecoder> Debug for LazyExpandedValue<'top, Encoding> { +impl<'top, Encoding: Decoder> Debug for LazyExpandedValue<'top, Encoding> { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "{:?}", self.source) } } -impl<'top, Encoding: LazyDecoder> LazyExpandedValue<'top, Encoding> { +impl<'top, Encoding: Decoder> LazyExpandedValue<'top, Encoding> { pub(crate) fn from_literal( context: EncodingContextRef<'top>, value: Encoding::Value<'top>, @@ -652,7 +652,7 @@ impl<'top, Encoding: LazyDecoder> LazyExpandedValue<'top, Encoding> { } } -impl<'top, Encoding: LazyDecoder> From> +impl<'top, Encoding: Decoder> From> for LazyValue<'top, Encoding> { fn from(expanded_value: LazyExpandedValue<'top, Encoding>) -> Self { @@ -660,7 +660,7 @@ impl<'top, Encoding: LazyDecoder> From> } } -impl<'top, Encoding: LazyDecoder> From> +impl<'top, Encoding: Decoder> From> for LazyStruct<'top, Encoding> { fn from(expanded_struct: LazyExpandedStruct<'top, Encoding>) -> Self { @@ -668,40 +668,36 @@ impl<'top, Encoding: LazyDecoder> From> } } -impl<'top, Encoding: LazyDecoder> From> - for LazySExp<'top, Encoding> -{ +impl<'top, Encoding: Decoder> From> for LazySExp<'top, Encoding> { fn from(expanded_sexp: LazyExpandedSExp<'top, Encoding>) -> Self { LazySExp { expanded_sexp } } } -impl<'top, Encoding: LazyDecoder> From> - for LazyList<'top, Encoding> -{ +impl<'top, Encoding: Decoder> From> for LazyList<'top, Encoding> { fn from(expanded_list: LazyExpandedList<'top, Encoding>) -> Self { LazyList { expanded_list } } } -pub enum ExpandedAnnotationsSource<'top, Encoding: LazyDecoder> { +pub enum ExpandedAnnotationsSource<'top, Encoding: Decoder> { ValueLiteral(Encoding::AnnotationsIterator<'top>), Template(SymbolsIterator<'top>), // TODO: This is a placeholder impl and always returns an empty iterator Constructed(Box>> + 'top>), } -pub struct ExpandedAnnotationsIterator<'top, Encoding: LazyDecoder> { +pub struct ExpandedAnnotationsIterator<'top, Encoding: Decoder> { source: ExpandedAnnotationsSource<'top, Encoding>, } -impl<'top, Encoding: LazyDecoder> ExpandedAnnotationsIterator<'top, Encoding> { +impl<'top, Encoding: Decoder> ExpandedAnnotationsIterator<'top, Encoding> { pub fn new(source: ExpandedAnnotationsSource<'top, Encoding>) -> Self { Self { source } } } -impl<'top, Encoding: LazyDecoder> Iterator for ExpandedAnnotationsIterator<'top, Encoding> { +impl<'top, Encoding: Decoder> Iterator for ExpandedAnnotationsIterator<'top, Encoding> { type Item = IonResult>; fn next(&mut self) -> Option { @@ -722,7 +718,7 @@ impl<'top, Encoding: LazyDecoder> Iterator for ExpandedAnnotationsIterator<'top, // hold a 'top reference to a bump allocation instead of a static reference to a heap allocation. // This will enable us to remove several calls to `clone()`, which can be much slower than copies. #[derive(Clone)] -pub enum ExpandedValueRef<'top, Encoding: LazyDecoder> { +pub enum ExpandedValueRef<'top, Encoding: Decoder> { Null(IonType), Bool(bool), Int(Int), @@ -738,7 +734,7 @@ pub enum ExpandedValueRef<'top, Encoding: LazyDecoder> { Struct(LazyExpandedStruct<'top, Encoding>), } -impl<'top, Encoding: LazyDecoder> PartialEq for ExpandedValueRef<'top, Encoding> { +impl<'top, Encoding: Decoder> PartialEq for ExpandedValueRef<'top, Encoding> { fn eq(&self, other: &Self) -> bool { use ExpandedValueRef::*; match (self, other) { @@ -762,7 +758,7 @@ impl<'top, Encoding: LazyDecoder> PartialEq for ExpandedValueRef<'top, Encoding> } } -impl<'top, Encoding: LazyDecoder> ExpandedValueRef<'top, Encoding> { +impl<'top, Encoding: Decoder> ExpandedValueRef<'top, Encoding> { fn expected(self, expected_name: &str) -> IonResult { IonResult::decoding_error(format!( "expected a(n) {} but found a {:?}", @@ -902,7 +898,7 @@ impl<'top, Encoding: LazyDecoder> ExpandedValueRef<'top, Encoding> { } } -impl<'top, D: LazyDecoder> Debug for ExpandedValueRef<'top, D> { +impl<'top, D: Decoder> Debug for ExpandedValueRef<'top, D> { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { use ExpandedValueRef::*; match self { @@ -924,7 +920,7 @@ impl<'top, D: LazyDecoder> Debug for ExpandedValueRef<'top, D> { } } -impl<'top, Encoding: LazyDecoder> ExpandedValueRef<'top, Encoding> { +impl<'top, Encoding: Decoder> ExpandedValueRef<'top, Encoding> { fn from_template( context: EncodingContextRef<'top>, environment: Environment<'top, Encoding>, diff --git a/src/lazy/expanded/sequence.rs b/src/lazy/expanded/sequence.rs index 15786948..9f297625 100644 --- a/src/lazy/expanded/sequence.rs +++ b/src/lazy/expanded/sequence.rs @@ -1,7 +1,7 @@ use bumpalo::collections::Vec as BumpVec; use crate::element::iterators::SymbolsIterator; -use crate::lazy::decoder::{LazyDecoder, LazyRawSequence, LazyRawValueExpr, RawValueExpr}; +use crate::lazy::decoder::{Decoder, LazyRawSequence, LazyRawValueExpr, RawValueExpr}; use crate::lazy::expanded::macro_evaluator::{MacroEvaluator, RawEExpression, ValueExpr}; use crate::lazy::expanded::template::{ AnnotationsRange, ExprRange, TemplateMacroRef, TemplateSequenceIterator, @@ -28,11 +28,11 @@ use crate::{IonError, IonResult, IonType}; /// The `Environment` would contain the expressions `1`, `2` and `3`, corresponding to parameters /// `x`, `y`, and `z` respectively. #[derive(Copy, Clone, Debug)] -pub struct Environment<'top, D: LazyDecoder> { +pub struct Environment<'top, D: Decoder> { expressions: &'top [ValueExpr<'top, D>], } -impl<'top, D: LazyDecoder> Environment<'top, D> { +impl<'top, D: Decoder> Environment<'top, D> { pub(crate) fn new(args: BumpVec<'top, ValueExpr<'top, D>>) -> Self { Environment { expressions: args.into_bump_slice(), @@ -66,7 +66,7 @@ impl<'top, D: LazyDecoder> Environment<'top, D> { /// The data source for a [`LazyExpandedList`]. #[derive(Clone, Copy)] -pub enum ExpandedListSource<'top, D: LazyDecoder> { +pub enum ExpandedListSource<'top, D: Decoder> { /// The list was a value literal in the input stream. ValueLiteral(D::List<'top>), /// The list was part of a template definition. @@ -82,12 +82,12 @@ pub enum ExpandedListSource<'top, D: LazyDecoder> { /// A list that may have come from either a value literal in the input stream or from evaluating /// a template. #[derive(Clone, Copy)] -pub struct LazyExpandedList<'top, D: LazyDecoder> { +pub struct LazyExpandedList<'top, D: Decoder> { pub(crate) context: EncodingContextRef<'top>, pub(crate) source: ExpandedListSource<'top, D>, } -impl<'top, D: LazyDecoder> LazyExpandedList<'top, D> { +impl<'top, D: Decoder> LazyExpandedList<'top, D> { pub fn from_literal( context: EncodingContextRef<'top>, list: D::List<'top>, @@ -159,7 +159,7 @@ impl<'top, D: LazyDecoder> LazyExpandedList<'top, D> { } /// The source of child values iterated over by an [`ExpandedListIterator`]. -pub enum ExpandedListIteratorSource<'top, D: LazyDecoder> { +pub enum ExpandedListIteratorSource<'top, D: Decoder> { ValueLiteral( // Giving the list iterator its own evaluator means that we can abandon the iterator // at any time without impacting the evaluation state of its parent container. @@ -171,12 +171,12 @@ pub enum ExpandedListIteratorSource<'top, D: LazyDecoder> { } /// Iterates over the child values of a [`LazyExpandedList`]. -pub struct ExpandedListIterator<'top, D: LazyDecoder> { +pub struct ExpandedListIterator<'top, D: Decoder> { context: EncodingContextRef<'top>, source: ExpandedListIteratorSource<'top, D>, } -impl<'top, D: LazyDecoder> Iterator for ExpandedListIterator<'top, D> { +impl<'top, D: Decoder> Iterator for ExpandedListIterator<'top, D> { type Item = IonResult>; fn next(&mut self) -> Option { @@ -191,7 +191,7 @@ impl<'top, D: LazyDecoder> Iterator for ExpandedListIterator<'top, D> { /// The data source for a [`LazyExpandedSExp`]. #[derive(Clone, Copy)] -pub enum ExpandedSExpSource<'top, D: LazyDecoder> { +pub enum ExpandedSExpSource<'top, D: Decoder> { /// The SExp was a value literal in the input stream. ValueLiteral(D::SExp<'top>), /// The SExp was part of a template definition. @@ -206,12 +206,12 @@ pub enum ExpandedSExpSource<'top, D: LazyDecoder> { /// An s-expression that may have come from either a value literal in the input stream or from /// evaluating a template. #[derive(Clone, Copy)] -pub struct LazyExpandedSExp<'top, D: LazyDecoder> { +pub struct LazyExpandedSExp<'top, D: Decoder> { pub(crate) source: ExpandedSExpSource<'top, D>, pub(crate) context: EncodingContextRef<'top>, } -impl<'top, D: LazyDecoder> LazyExpandedSExp<'top, D> { +impl<'top, D: Decoder> LazyExpandedSExp<'top, D> { pub fn source(&self) -> ExpandedSExpSource<'top, D> { self.source } @@ -282,7 +282,7 @@ impl<'top, D: LazyDecoder> LazyExpandedSExp<'top, D> { } /// The source of child values iterated over by an [`ExpandedSExpIterator`]. -pub enum ExpandedSExpIteratorSource<'top, D: LazyDecoder> { +pub enum ExpandedSExpIteratorSource<'top, D: Decoder> { ValueLiteral( // Giving the sexp iterator its own evaluator means that we can abandon the iterator // at any time without impacting the evaluation state of its parent container. @@ -294,12 +294,12 @@ pub enum ExpandedSExpIteratorSource<'top, D: LazyDecoder> { } /// Iterates over the child values of a [`LazyExpandedSExp`]. -pub struct ExpandedSExpIterator<'top, D: LazyDecoder> { +pub struct ExpandedSExpIterator<'top, D: Decoder> { context: EncodingContextRef<'top>, source: ExpandedSExpIteratorSource<'top, D>, } -impl<'top, D: LazyDecoder> Iterator for ExpandedSExpIterator<'top, D> { +impl<'top, D: Decoder> Iterator for ExpandedSExpIterator<'top, D> { type Item = IonResult>; fn next(&mut self) -> Option { @@ -314,7 +314,7 @@ impl<'top, D: LazyDecoder> Iterator for ExpandedSExpIterator<'top, D> { /// For both lists and s-expressions, yields the next sequence value by either continuing a macro /// evaluation already in progress or reading the next item from the input stream. -fn expand_next_sequence_value<'top, D: LazyDecoder>( +fn expand_next_sequence_value<'top, D: Decoder>( context: EncodingContextRef<'top>, evaluator: &mut MacroEvaluator<'top, D>, iter: &mut impl Iterator>>, diff --git a/src/lazy/expanded/struct.rs b/src/lazy/expanded/struct.rs index 0ac22ff7..013f1dc1 100644 --- a/src/lazy/expanded/struct.rs +++ b/src/lazy/expanded/struct.rs @@ -2,7 +2,7 @@ use std::ops::ControlFlow; use crate::element::iterators::SymbolsIterator; use crate::lazy::decoder::private::{LazyRawStructPrivate, RawStructUnexpandedFieldsIterator}; -use crate::lazy::decoder::{LazyDecoder, LazyRawFieldName, LazyRawStruct}; +use crate::lazy::decoder::{Decoder, LazyRawFieldName, LazyRawStruct}; use crate::lazy::expanded::macro_evaluator::{ MacroEvaluator, MacroExpr, RawEExpression, ValueExpr, }; @@ -26,7 +26,7 @@ use crate::{IonError, IonResult, RawSymbolRef, SymbolRef}; // template's struct body into `UnexpandedField` instances. The `ExpandedStructIterator` unpacks // and expands the field as part of its iteration process. #[derive(Debug, Clone, Copy)] -pub enum UnexpandedField<'top, D: LazyDecoder> { +pub enum UnexpandedField<'top, D: Decoder> { RawNameValue(EncodingContextRef<'top>, D::FieldName<'top>, D::Value<'top>), RawNameEExp(EncodingContextRef<'top>, D::FieldName<'top>, D::EExp<'top>), RawEExp(EncodingContextRef<'top>, D::EExp<'top>), @@ -42,14 +42,14 @@ pub enum UnexpandedField<'top, D: LazyDecoder> { } #[derive(Debug, Clone, Copy)] -pub struct LazyExpandedField<'top, D: LazyDecoder> { +pub struct LazyExpandedField<'top, D: Decoder> { name: LazyExpandedFieldName<'top, D>, value: LazyExpandedValue<'top, D>, } -impl<'top, D: LazyDecoder> LazyExpandedField<'top, D> {} +impl<'top, D: Decoder> LazyExpandedField<'top, D> {} -impl<'top, D: LazyDecoder> LazyExpandedField<'top, D> { +impl<'top, D: Decoder> LazyExpandedField<'top, D> { pub fn new(name: LazyExpandedFieldName<'top, D>, value: LazyExpandedValue<'top, D>) -> Self { Self { name, value } } @@ -63,7 +63,7 @@ impl<'top, D: LazyDecoder> LazyExpandedField<'top, D> { } } -impl<'top, D: LazyDecoder> LazyExpandedField<'top, D> { +impl<'top, D: Decoder> LazyExpandedField<'top, D> { fn from_raw_field( context: EncodingContextRef<'top>, name: D::FieldName<'top>, @@ -88,13 +88,13 @@ impl<'top, D: LazyDecoder> LazyExpandedField<'top, D> { } #[derive(Debug, Clone, Copy)] -pub enum LazyExpandedFieldName<'top, D: LazyDecoder> { +pub enum LazyExpandedFieldName<'top, D: Decoder> { RawName(EncodingContextRef<'top>, D::FieldName<'top>), TemplateName(TemplateMacroRef<'top>, SymbolRef<'top>), // TODO: `Constructed` needed for names in `(make_struct ...)` } -impl<'top, D: LazyDecoder> LazyExpandedFieldName<'top, D> { +impl<'top, D: Decoder> LazyExpandedFieldName<'top, D> { pub(crate) fn read(&self) -> IonResult> { match self { LazyExpandedFieldName::RawName(context, name) => match name.read()? { @@ -122,7 +122,7 @@ impl<'top, D: LazyDecoder> LazyExpandedFieldName<'top, D> { } #[derive(Copy, Clone)] -pub enum ExpandedStructSource<'top, D: LazyDecoder> { +pub enum ExpandedStructSource<'top, D: Decoder> { ValueLiteral(D::Struct<'top>), Template( Environment<'top, D>, @@ -135,13 +135,13 @@ pub enum ExpandedStructSource<'top, D: LazyDecoder> { } #[derive(Copy, Clone)] -pub struct LazyExpandedStruct<'top, D: LazyDecoder> { +pub struct LazyExpandedStruct<'top, D: Decoder> { pub(crate) context: EncodingContextRef<'top>, pub(crate) source: ExpandedStructSource<'top, D>, } #[cfg(feature = "experimental-tooling-apis")] -impl<'top, D: LazyDecoder> LazyExpandedStruct<'top, D> { +impl<'top, D: Decoder> LazyExpandedStruct<'top, D> { pub fn context(&self) -> EncodingContextRef<'top> { self.context } @@ -150,7 +150,7 @@ impl<'top, D: LazyDecoder> LazyExpandedStruct<'top, D> { } } -impl<'top, D: LazyDecoder> LazyExpandedStruct<'top, D> { +impl<'top, D: Decoder> LazyExpandedStruct<'top, D> { pub fn from_literal( context: EncodingContextRef<'top>, sexp: D::Struct<'top>, @@ -321,7 +321,7 @@ impl<'top, D: LazyDecoder> LazyExpandedStruct<'top, D> { } } -pub enum ExpandedStructIteratorSource<'top, D: LazyDecoder> { +pub enum ExpandedStructIteratorSource<'top, D: Decoder> { // The struct we're iterating over is a literal in the data stream. It may contain // e-expressions that need to be evaluated. ValueLiteral( @@ -339,7 +339,7 @@ pub enum ExpandedStructIteratorSource<'top, D: LazyDecoder> { // TODO: Constructed } -pub struct ExpandedStructIterator<'top, D: LazyDecoder> { +pub struct ExpandedStructIterator<'top, D: Decoder> { // Each variant of 'source' below holds its own encoding context reference source: ExpandedStructIteratorSource<'top, D>, // Stores information about any operations that are still in progress. @@ -348,7 +348,7 @@ pub struct ExpandedStructIterator<'top, D: LazyDecoder> { /// Ion 1.1's struct is very versatile, and supports a variety of expansion operations. This /// types indicates which operation is in the process of being carried out. -enum ExpandedStructIteratorState<'top, D: LazyDecoder> { +enum ExpandedStructIteratorState<'top, D: Decoder> { // The iterator is not performing any operations. It is ready to pull the next field from its // source. ReadingFieldFromSource, @@ -375,7 +375,7 @@ enum ExpandedStructIteratorState<'top, D: LazyDecoder> { ), } -impl<'top, D: LazyDecoder> Iterator for ExpandedStructIterator<'top, D> { +impl<'top, D: Decoder> Iterator for ExpandedStructIterator<'top, D> { type Item = IonResult>; fn next(&mut self) -> Option { @@ -410,7 +410,7 @@ impl<'top, D: LazyDecoder> Iterator for ExpandedStructIterator<'top, D> { // // 'top: The lifetime associated with the top-level value we're currently reading at some depth. // D: The decoder being used to read the Ion data stream. For example: `TextEncoding_1_1` -impl<'top, D: LazyDecoder> ExpandedStructIterator<'top, D> { +impl<'top, D: Decoder> ExpandedStructIterator<'top, D> { /// Pulls the next expanded field from the raw source struct. The field returned may correspond /// to a `(name, value literal)` pair in the raw struct, or it may be the product of a macro /// evaluation. diff --git a/src/lazy/expanded/template.rs b/src/lazy/expanded/template.rs index fef29e00..0e24cc7a 100644 --- a/src/lazy/expanded/template.rs +++ b/src/lazy/expanded/template.rs @@ -3,7 +3,7 @@ use std::fmt; use std::fmt::{Debug, Formatter}; use std::ops::{Deref, Range}; -use crate::lazy::decoder::LazyDecoder; +use crate::lazy::decoder::Decoder; use crate::lazy::expanded::macro_evaluator::{MacroEvaluator, MacroExpr, ValueExpr}; use crate::lazy::expanded::macro_table::MacroRef; use crate::lazy::expanded::r#struct::UnexpandedField; @@ -143,7 +143,7 @@ impl<'top> Deref for TemplateMacroRef<'top> { } /// Steps over the child expressions of a list or s-expression found in the body of a template. -pub struct TemplateSequenceIterator<'top, D: LazyDecoder> { +pub struct TemplateSequenceIterator<'top, D: Decoder> { context: EncodingContextRef<'top>, template: TemplateMacroRef<'top>, evaluator: MacroEvaluator<'top, D>, @@ -151,7 +151,7 @@ pub struct TemplateSequenceIterator<'top, D: LazyDecoder> { index: usize, } -impl<'top, D: LazyDecoder> TemplateSequenceIterator<'top, D> { +impl<'top, D: Decoder> TemplateSequenceIterator<'top, D> { pub fn new( context: EncodingContextRef<'top>, evaluator: MacroEvaluator<'top, D>, @@ -168,7 +168,7 @@ impl<'top, D: LazyDecoder> TemplateSequenceIterator<'top, D> { } } -impl<'top, D: LazyDecoder> Iterator for TemplateSequenceIterator<'top, D> { +impl<'top, D: Decoder> Iterator for TemplateSequenceIterator<'top, D> { type Item = IonResult>; fn next(&mut self) -> Option { @@ -247,7 +247,7 @@ impl<'top, D: LazyDecoder> Iterator for TemplateSequenceIterator<'top, D> { /// An iterator that pulls expressions from a template body and wraps them in a [`UnexpandedField`] to /// mimic reading them from input. The [`LazyExpandedStruct`](crate::lazy::expanded::struct) handles /// evaluating any macro invocations that this yields. -pub struct TemplateStructUnexpandedFieldsIterator<'top, D: LazyDecoder> { +pub struct TemplateStructUnexpandedFieldsIterator<'top, D: Decoder> { context: EncodingContextRef<'top>, environment: Environment<'top, D>, template: TemplateMacroRef<'top>, @@ -255,13 +255,13 @@ pub struct TemplateStructUnexpandedFieldsIterator<'top, D: LazyDecoder> { index: usize, } -impl<'top, D: LazyDecoder> TemplateStructUnexpandedFieldsIterator<'top, D> { +impl<'top, D: Decoder> TemplateStructUnexpandedFieldsIterator<'top, D> { pub fn context(&self) -> EncodingContextRef<'top> { self.context } } -impl<'top, D: LazyDecoder> TemplateStructUnexpandedFieldsIterator<'top, D> { +impl<'top, D: Decoder> TemplateStructUnexpandedFieldsIterator<'top, D> { pub fn new( context: EncodingContextRef<'top>, environment: Environment<'top, D>, @@ -278,7 +278,7 @@ impl<'top, D: LazyDecoder> TemplateStructUnexpandedFieldsIterator<'top, D> { } } -impl<'top, D: LazyDecoder> Iterator for TemplateStructUnexpandedFieldsIterator<'top, D> { +impl<'top, D: Decoder> Iterator for TemplateStructUnexpandedFieldsIterator<'top, D> { type Item = IonResult>; fn next(&mut self) -> Option { @@ -698,7 +698,7 @@ impl<'top> TemplateMacroInvocation<'top> { pub fn id(&self) -> MacroIdRef<'top> { MacroIdRef::LocalAddress(self.invoked_macro.address()) } - pub fn arguments( + pub fn arguments( &self, environment: Environment<'top, D>, ) -> TemplateMacroInvocationArgsIterator<'top, D> { @@ -718,20 +718,20 @@ impl<'top> TemplateMacroInvocation<'top> { } } -impl<'top, D: LazyDecoder> From> for MacroExpr<'top, D> { +impl<'top, D: Decoder> From> for MacroExpr<'top, D> { fn from(value: TemplateMacroInvocation<'top>) -> Self { MacroExpr::TemplateMacro(value) } } /// Steps over the argument expressions passed to a macro invocation found in a template body. -pub struct TemplateMacroInvocationArgsIterator<'top, D: LazyDecoder> { +pub struct TemplateMacroInvocationArgsIterator<'top, D: Decoder> { environment: Environment<'top, D>, invocation: TemplateMacroInvocation<'top>, arg_index: usize, } -impl<'top, D: LazyDecoder> TemplateMacroInvocationArgsIterator<'top, D> { +impl<'top, D: Decoder> TemplateMacroInvocationArgsIterator<'top, D> { pub fn new( environment: Environment<'top, D>, invocation: TemplateMacroInvocation<'top>, @@ -744,7 +744,7 @@ impl<'top, D: LazyDecoder> TemplateMacroInvocationArgsIterator<'top, D> { } } -impl<'top, D: LazyDecoder> Iterator for TemplateMacroInvocationArgsIterator<'top, D> { +impl<'top, D: Decoder> Iterator for TemplateMacroInvocationArgsIterator<'top, D> { type Item = IonResult>; fn next(&mut self) -> Option { diff --git a/src/lazy/lazy_value_cache.rs b/src/lazy/lazy_value_cache.rs index 7e9df0b9..7e3fd74e 100644 --- a/src/lazy/lazy_value_cache.rs +++ b/src/lazy/lazy_value_cache.rs @@ -1,6 +1,6 @@ -use crate::lazy::decoder::{LazyDecoder, LazyRawValueExpr}; +use crate::lazy::decoder::{Decoder, LazyRawValueExpr}; use bumpalo::collections::Vec as BumpVec; -pub struct RawValueExprCache<'top, D: LazyDecoder> { +pub struct RawValueExprCache<'top, D: Decoder> { values: BumpVec<'top, LazyRawValueExpr<'top, D>>, } diff --git a/src/lazy/never.rs b/src/lazy/never.rs index a022347d..80e11dec 100644 --- a/src/lazy/never.rs +++ b/src/lazy/never.rs @@ -1,7 +1,7 @@ use std::fmt::Debug; use std::ops::Range; -use crate::lazy::decoder::{HasRange, HasSpan, LazyDecoder, LazyRawValueExpr}; +use crate::lazy::decoder::{Decoder, HasRange, HasSpan, LazyRawValueExpr}; use crate::lazy::encoder::annotation_seq::AnnotationSeq; use crate::lazy::encoder::value_writer::internal::{FieldEncoder, MakeValueWriter}; use crate::lazy::encoder::value_writer::{ @@ -34,7 +34,7 @@ impl HasRange for Never { // Ion 1.0 uses `Never` as a placeholder type for MacroInvocation. // The compiler should optimize these methods away. -impl<'top, D: LazyDecoder = Self>> RawEExpression<'top, D> for Never { +impl<'top, D: Decoder = Self>> RawEExpression<'top, D> for Never { // These use Box to avoid defining yet another placeholder type. type RawArgumentsIterator<'a> = Box>>>; @@ -47,7 +47,7 @@ impl<'top, D: LazyDecoder = Self>> RawEExpression<'top, D> for Never } } -impl<'top, D: LazyDecoder> From for MacroExpr<'top, D> { +impl<'top, D: Decoder> From for MacroExpr<'top, D> { fn from(_value: Never) -> Self { unreachable!("macro in Ion 1.0 (method: into)") } diff --git a/src/lazy/raw_stream_item.rs b/src/lazy/raw_stream_item.rs index ac1f0847..be497242 100644 --- a/src/lazy/raw_stream_item.rs +++ b/src/lazy/raw_stream_item.rs @@ -1,4 +1,4 @@ -use crate::lazy::decoder::{HasRange, HasSpan, LazyDecoder}; +use crate::lazy::decoder::{Decoder, HasRange, HasSpan}; use crate::lazy::span::Span; use crate::result::IonFailure; use crate::{IonError, IonResult}; @@ -22,9 +22,9 @@ pub enum RawStreamItem { } pub type LazyRawStreamItem<'top, D> = RawStreamItem< - ::VersionMarker<'top>, - ::Value<'top>, - ::EExp<'top>, + ::VersionMarker<'top>, + ::Value<'top>, + ::EExp<'top>, >; impl HasRange diff --git a/src/lazy/raw_value_ref.rs b/src/lazy/raw_value_ref.rs index 994189f7..277082e4 100644 --- a/src/lazy/raw_value_ref.rs +++ b/src/lazy/raw_value_ref.rs @@ -1,5 +1,5 @@ use crate::lazy::bytes_ref::BytesRef; -use crate::lazy::decoder::LazyDecoder; +use crate::lazy::decoder::Decoder; use crate::lazy::str_ref::StrRef; use crate::result::IonFailure; use crate::{Decimal, Int, IonResult, IonType, RawSymbolRef, Timestamp}; @@ -11,7 +11,7 @@ use std::fmt::{Debug, Formatter}; /// /// For a resolved version of this type, see [crate::lazy::value_ref::ValueRef]. #[derive(Copy, Clone)] -pub enum RawValueRef<'top, D: LazyDecoder> { +pub enum RawValueRef<'top, D: Decoder> { Null(IonType), Bool(bool), Int(Int), @@ -28,7 +28,7 @@ pub enum RawValueRef<'top, D: LazyDecoder> { } // Provides equality for scalar types, but not containers. -impl<'top, D: LazyDecoder> PartialEq for RawValueRef<'top, D> { +impl<'top, D: Decoder> PartialEq for RawValueRef<'top, D> { fn eq(&self, other: &Self) -> bool { use RawValueRef::*; match (self, other) { @@ -49,7 +49,7 @@ impl<'top, D: LazyDecoder> PartialEq for RawValueRef<'top, D> { } } -impl<'top, D: LazyDecoder> Debug for RawValueRef<'top, D> { +impl<'top, D: Decoder> Debug for RawValueRef<'top, D> { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { match self { RawValueRef::Null(ion_type) => write!(f, "null.{}", ion_type), @@ -69,7 +69,7 @@ impl<'top, D: LazyDecoder> Debug for RawValueRef<'top, D> { } } -impl<'top, D: LazyDecoder> RawValueRef<'top, D> { +impl<'top, D: Decoder> RawValueRef<'top, D> { pub fn expect_null(self) -> IonResult { if let RawValueRef::Null(ion_type) = self { Ok(ion_type) diff --git a/src/lazy/reader.rs b/src/lazy/reader.rs index cdb0ca05..f847fc0f 100644 --- a/src/lazy/reader.rs +++ b/src/lazy/reader.rs @@ -3,7 +3,7 @@ use crate::element::reader::ElementReader; use crate::element::Element; use crate::lazy::any_encoding::AnyEncoding; -use crate::lazy::decoder::LazyDecoder; +use crate::lazy::decoder::Decoder; use crate::lazy::encoding::{BinaryEncoding_1_0, BinaryEncoding_1_1, TextEncoding_1_0, TextEncoding_1_1}; use crate::lazy::streaming_raw_reader::IonInput; use crate::lazy::system_reader::{ @@ -64,17 +64,17 @@ use crate::{IonError, IonResult}; ///# #[cfg(not(feature = "experimental-reader-writer"))] ///# fn main() -> IonResult<()> { Ok(()) } /// ``` -pub struct IonReader { +pub struct IonReader { system_reader: SystemReader, } -pub(crate) enum NextApplicationValue<'top, D: LazyDecoder> { +pub(crate) enum NextApplicationValue<'top, D: Decoder> { ApplicationValue(LazyValue<'top, D>), SystemValue, EndOfStream, } -impl IonReader { +impl IonReader { /// Returns the next top-level value in the input stream as `Ok(Some(lazy_value))`. /// If there are no more top-level values in the stream, returns `Ok(None)`. /// If the next value is incomplete (that is: only part of it is in the input buffer) or if the @@ -126,9 +126,9 @@ pub type TextReader_1_1 = IonReader; pub type Reader = IonReader; impl Reader { - pub fn new(ion_data: Input) -> Reader { + pub fn new(ion_data: Input) -> IonResult> { let system_reader = SystemAnyReader::new(ion_data); - IonReader { system_reader } + Ok(IonReader { system_reader }) } } @@ -154,11 +154,11 @@ impl TextReader_1_1 { } } -pub struct LazyElementIterator<'iter, Encoding: LazyDecoder, Input: IonInput> { +pub struct LazyElementIterator<'iter, Encoding: Decoder, Input: IonInput> { lazy_reader: &'iter mut IonReader, } -impl<'iter, Encoding: LazyDecoder, Input: IonInput> Iterator +impl<'iter, Encoding: Decoder, Input: IonInput> Iterator for LazyElementIterator<'iter, Encoding, Input> { type Item = IonResult; @@ -172,7 +172,7 @@ impl<'iter, Encoding: LazyDecoder, Input: IonInput> Iterator } } -impl ElementReader +impl ElementReader for IonReader { type ElementIterator<'a> = LazyElementIterator<'a, Encoding, Input> where Self: 'a,; @@ -195,7 +195,7 @@ impl ElementReader mod tests { use crate::element::element_writer::ElementWriter; use crate::element::Element; - use crate::lazy::encoder::writer::IonWriter; + use crate::lazy::encoder::writer::Writer; use crate::lazy::value_ref::ValueRef; use crate::write_config::WriteConfig; use crate::{ion_list, ion_sexp, ion_struct, Int, IonResult, IonType}; @@ -205,7 +205,7 @@ mod tests { fn to_binary_ion(text_ion: &str) -> IonResult> { let buffer = Vec::new(); let config = WriteConfig::::new(); - let mut writer = IonWriter::with_config(config, buffer)?; + let mut writer = Writer::with_config(config, buffer)?; let elements = Element::read_all(text_ion)?; writer.write_elements(&elements)?; writer.flush()?; diff --git a/src/lazy/sequence.rs b/src/lazy/sequence.rs index ff6c237b..3e7a22ad 100644 --- a/src/lazy/sequence.rs +++ b/src/lazy/sequence.rs @@ -1,7 +1,7 @@ use std::fmt; use std::fmt::{Debug, Formatter}; -use crate::lazy::decoder::LazyDecoder; +use crate::lazy::decoder::Decoder; use crate::lazy::encoding::BinaryEncoding_1_0; use crate::lazy::expanded::sequence::{ ExpandedListIterator, ExpandedSExpIterator, LazyExpandedList, LazyExpandedSExp, @@ -52,13 +52,13 @@ use crate::{IonError, IonResult}; ///# fn main() -> IonResult<()> { Ok(()) } /// ``` #[derive(Copy, Clone)] -pub struct LazyList<'top, D: LazyDecoder> { +pub struct LazyList<'top, D: Decoder> { pub(crate) expanded_list: LazyExpandedList<'top, D>, } pub type LazyBinarySequence<'top, 'data> = LazyList<'top, BinaryEncoding_1_0>; -impl<'top, D: LazyDecoder> LazyList<'top, D> { +impl<'top, D: Decoder> LazyList<'top, D> { /// Returns an iterator over the values in this sequence. See: [`LazyValue`]. pub fn iter(&self) -> ListIterator<'top, D> { ListIterator { @@ -115,7 +115,7 @@ impl<'top, D: LazyDecoder> LazyList<'top, D> { } } -impl<'top, D: LazyDecoder> TryFrom> for Sequence { +impl<'top, D: Decoder> TryFrom> for Sequence { type Error = IonError; fn try_from(lazy_sequence: LazyList<'top, D>) -> Result { @@ -128,7 +128,7 @@ impl<'top, D: LazyDecoder> TryFrom> for Sequence { } } -impl<'top, D: LazyDecoder> TryFrom> for Element { +impl<'top, D: Decoder> TryFrom> for Element { type Error = IonError; fn try_from(lazy_list: LazyList<'top, D>) -> Result { @@ -139,7 +139,7 @@ impl<'top, D: LazyDecoder> TryFrom> for Element { } } -impl<'a, 'top, 'data: 'top, D: LazyDecoder> IntoIterator for &'a LazyList<'top, D> { +impl<'a, 'top, 'data: 'top, D: Decoder> IntoIterator for &'a LazyList<'top, D> { type Item = IonResult>; type IntoIter = ListIterator<'top, D>; @@ -148,11 +148,11 @@ impl<'a, 'top, 'data: 'top, D: LazyDecoder> IntoIterator for &'a LazyList<'top, } } -pub struct ListIterator<'top, D: LazyDecoder> { +pub struct ListIterator<'top, D: Decoder> { expanded_list_iter: ExpandedListIterator<'top, D>, } -impl<'top, D: LazyDecoder> Iterator for ListIterator<'top, D> { +impl<'top, D: Decoder> Iterator for ListIterator<'top, D> { type Item = IonResult>; fn next(&mut self) -> Option { @@ -167,7 +167,7 @@ impl<'top, D: LazyDecoder> Iterator for ListIterator<'top, D> { } } -impl<'top, D: LazyDecoder> Debug for LazyList<'top, D> { +impl<'top, D: Decoder> Debug for LazyList<'top, D> { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { write!(f, "[")?; for value in self { @@ -182,11 +182,11 @@ impl<'top, D: LazyDecoder> Debug for LazyList<'top, D> { // ===== SExps ===== #[derive(Copy, Clone)] -pub struct LazySExp<'top, D: LazyDecoder> { +pub struct LazySExp<'top, D: Decoder> { pub(crate) expanded_sexp: LazyExpandedSExp<'top, D>, } -impl<'top, D: LazyDecoder> Debug for LazySExp<'top, D> { +impl<'top, D: Decoder> Debug for LazySExp<'top, D> { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { write!(f, "(")?; for value in self { @@ -198,7 +198,7 @@ impl<'top, D: LazyDecoder> Debug for LazySExp<'top, D> { } } -impl<'top, D: LazyDecoder> LazySExp<'top, D> { +impl<'top, D: Decoder> LazySExp<'top, D> { pub fn lower(&self) -> LazyExpandedSExp<'top, D> { self.expanded_sexp } @@ -249,7 +249,7 @@ impl<'top, D: LazyDecoder> LazySExp<'top, D> { } } -impl<'top, D: LazyDecoder> TryFrom> for Sequence { +impl<'top, D: Decoder> TryFrom> for Sequence { type Error = IonError; fn try_from(lazy_sequence: LazySExp<'top, D>) -> Result { @@ -262,7 +262,7 @@ impl<'top, D: LazyDecoder> TryFrom> for Sequence { } } -impl<'top, D: LazyDecoder> TryFrom> for Element { +impl<'top, D: Decoder> TryFrom> for Element { type Error = IonError; fn try_from(lazy_sequence: LazySExp<'top, D>) -> Result { @@ -273,7 +273,7 @@ impl<'top, D: LazyDecoder> TryFrom> for Element { } } -impl<'a, 'top, 'data: 'top, D: LazyDecoder> IntoIterator for &'a LazySExp<'top, D> { +impl<'a, 'top, 'data: 'top, D: Decoder> IntoIterator for &'a LazySExp<'top, D> { type Item = IonResult>; type IntoIter = SExpIterator<'top, D>; @@ -282,11 +282,11 @@ impl<'a, 'top, 'data: 'top, D: LazyDecoder> IntoIterator for &'a LazySExp<'top, } } -pub struct SExpIterator<'top, D: LazyDecoder> { +pub struct SExpIterator<'top, D: Decoder> { expanded_sexp_iter: ExpandedSExpIterator<'top, D>, } -impl<'top, D: LazyDecoder> Iterator for SExpIterator<'top, D> { +impl<'top, D: Decoder> Iterator for SExpIterator<'top, D> { type Item = IonResult>; fn next(&mut self) -> Option { diff --git a/src/lazy/streaming_raw_reader.rs b/src/lazy/streaming_raw_reader.rs index 86fb29df..06b61319 100644 --- a/src/lazy/streaming_raw_reader.rs +++ b/src/lazy/streaming_raw_reader.rs @@ -4,12 +4,12 @@ use std::io::{BufReader, Read, StdinLock}; use bumpalo::Bump as BumpAllocator; -use crate::lazy::decoder::{LazyDecoder, LazyRawReader}; +use crate::lazy::decoder::{Decoder, LazyRawReader}; use crate::lazy::raw_stream_item::LazyRawStreamItem; -use crate::IonResult; +use crate::{IonError, IonResult}; /// Wraps an implementation of [`IonDataSource`] and reads one top level value at a time from the input. -pub struct StreamingRawReader { +pub struct StreamingRawReader { // The Ion encoding that this reader recognizes. encoding: Encoding, // The StreamingRawReader works by reading the next value from the bytes currently available @@ -45,7 +45,7 @@ pub struct StreamingRawReader { const DEFAULT_IO_BUFFER_SIZE: usize = 4 * 1024; -impl StreamingRawReader { +impl StreamingRawReader { pub fn new(encoding: Encoding, input: Input) -> StreamingRawReader { StreamingRawReader { encoding, @@ -84,12 +84,13 @@ impl StreamingRawReader let bytes_read = end_position - starting_position; let input = unsafe { &mut *self.input.get() }; // If we've exhausted the buffer... - if bytes_read >= available_bytes.len() { - // ...try to pull more data from the data source. If there's nothing available, - // return the result we got. + if bytes_read >= available_bytes.len() || matches!(result, Err(IonError::Incomplete(_))) + { + // ...try to pull more data from the data source. If we get more data, try again. if input.fill_buffer()? > 0 { continue; } + // If there's nothing available, return the result we got. } // Mark those input bytes as having been consumed so they are not read again. input.consume(bytes_read); @@ -325,13 +326,13 @@ mod tests { use bumpalo::Bump as BumpAllocator; use crate::lazy::any_encoding::AnyEncoding; - use crate::lazy::decoder::{LazyDecoder, LazyRawValue}; + use crate::lazy::decoder::{Decoder, LazyRawValue}; use crate::lazy::raw_stream_item::LazyRawStreamItem; use crate::lazy::raw_value_ref::RawValueRef; use crate::lazy::streaming_raw_reader::{IonInput, StreamingRawReader}; use crate::{IonError, IonResult}; - fn expect_value<'a, D: LazyDecoder>( + fn expect_value<'a, D: Decoder>( actual: LazyRawStreamItem<'a, D>, expected: RawValueRef<'a, D>, ) -> IonResult<()> { diff --git a/src/lazy/struct.rs b/src/lazy/struct.rs index bb9d1717..986c492e 100644 --- a/src/lazy/struct.rs +++ b/src/lazy/struct.rs @@ -4,7 +4,7 @@ use std::fmt; use std::fmt::{Debug, Formatter}; use crate::element::builders::StructBuilder; -use crate::lazy::decoder::{LazyDecoder, LazyRawContainer}; +use crate::lazy::decoder::{Decoder, LazyRawContainer}; use crate::lazy::encoding::BinaryEncoding_1_0; use crate::lazy::expanded::r#struct::{ ExpandedStructIterator, ExpandedStructSource, LazyExpandedField, LazyExpandedStruct, @@ -49,7 +49,7 @@ use crate::{Annotations, Element, IntoAnnotatedElement, IonError, IonResult, Str ///# fn main() -> IonResult<()> { Ok(()) } /// ``` #[derive(Copy, Clone)] -pub struct LazyStruct<'top, D: LazyDecoder> { +pub struct LazyStruct<'top, D: Decoder> { pub(crate) expanded_struct: LazyExpandedStruct<'top, D>, } @@ -57,7 +57,7 @@ pub type LazyBinaryStruct_1_0<'top> = LazyStruct<'top, BinaryEncoding_1_0>; // Best-effort debug formatting for LazyStruct. Any failures that occur during reading will result // in the output being silently truncated. -impl<'top, D: LazyDecoder> Debug for LazyStruct<'top, D> { +impl<'top, D: Decoder> Debug for LazyStruct<'top, D> { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { write!(f, "{{")?; for field in self { @@ -72,7 +72,7 @@ impl<'top, D: LazyDecoder> Debug for LazyStruct<'top, D> { } } -impl<'top, D: LazyDecoder> LazyStruct<'top, D> { +impl<'top, D: Decoder> LazyStruct<'top, D> { /// Returns an iterator over this struct's fields. See [`LazyField`]. pub fn iter(&self) -> StructIterator<'top, D> { StructIterator { @@ -273,11 +273,11 @@ impl<'top, D: LazyDecoder> LazyStruct<'top, D> { } /// A single field within a [`LazyStruct`]. -pub struct LazyField<'top, D: LazyDecoder> { +pub struct LazyField<'top, D: Decoder> { pub(crate) expanded_field: LazyExpandedField<'top, D>, } -impl<'top, D: LazyDecoder> Debug for LazyField<'top, D> { +impl<'top, D: Decoder> Debug for LazyField<'top, D> { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { write!( f, @@ -288,7 +288,7 @@ impl<'top, D: LazyDecoder> Debug for LazyField<'top, D> { } } -impl<'top, D: LazyDecoder> LazyField<'top, D> { +impl<'top, D: Decoder> LazyField<'top, D> { /// Returns a symbol representing the name of this field. pub fn name(&self) -> IonResult> { self.expanded_field.name().read() @@ -303,11 +303,11 @@ impl<'top, D: LazyDecoder> LazyField<'top, D> { } } -pub struct StructIterator<'top, D: LazyDecoder> { +pub struct StructIterator<'top, D: Decoder> { pub(crate) expanded_struct_iter: ExpandedStructIterator<'top, D>, } -impl<'top, D: LazyDecoder> Iterator for StructIterator<'top, D> { +impl<'top, D: Decoder> Iterator for StructIterator<'top, D> { type Item = IonResult>; fn next(&mut self) -> Option { @@ -315,7 +315,7 @@ impl<'top, D: LazyDecoder> Iterator for StructIterator<'top, D> { } } -impl<'top, D: LazyDecoder> StructIterator<'top, D> { +impl<'top, D: Decoder> StructIterator<'top, D> { pub fn next_field(&mut self) -> IonResult>> { let expanded_field = match self.expanded_struct_iter.next() { Some(expanded_field) => expanded_field?, @@ -327,7 +327,7 @@ impl<'top, D: LazyDecoder> StructIterator<'top, D> { } } -impl<'top, D: LazyDecoder> TryFrom> for Struct { +impl<'top, D: Decoder> TryFrom> for Struct { type Error = IonError; fn try_from(lazy_struct: LazyStruct<'top, D>) -> Result { @@ -340,7 +340,7 @@ impl<'top, D: LazyDecoder> TryFrom> for Struct { } } -impl<'top, D: LazyDecoder> TryFrom> for Element { +impl<'top, D: Decoder> TryFrom> for Element { type Error = IonError; fn try_from(lazy_struct: LazyStruct<'top, D>) -> Result { @@ -350,7 +350,7 @@ impl<'top, D: LazyDecoder> TryFrom> for Element { } } -impl<'a, 'top, 'data: 'top, D: LazyDecoder> IntoIterator for &'a LazyStruct<'top, D> { +impl<'a, 'top, 'data: 'top, D: Decoder> IntoIterator for &'a LazyStruct<'top, D> { type Item = IonResult>; type IntoIter = StructIterator<'top, D>; diff --git a/src/lazy/system_reader.rs b/src/lazy/system_reader.rs index a4baf78a..18a36345 100644 --- a/src/lazy/system_reader.rs +++ b/src/lazy/system_reader.rs @@ -1,7 +1,7 @@ #![allow(non_camel_case_types)] use crate::lazy::any_encoding::AnyEncoding; -use crate::lazy::decoder::LazyDecoder; +use crate::lazy::decoder::Decoder; use crate::lazy::encoding::{BinaryEncoding_1_0, TextEncoding_1_0, TextEncoding_1_1}; use crate::lazy::expanded::{ExpandedValueRef, ExpandingReader, LazyExpandedValue}; use crate::lazy::streaming_raw_reader::{IonInput, StreamingRawReader}; @@ -69,7 +69,7 @@ const SYMBOLS: RawSymbolRef = RawSymbolRef::SymbolId(7); ///# #[cfg(not(feature = "experimental-reader-writer"))] ///# fn main() -> IonResult<()> { Ok(()) } /// ``` -pub struct SystemReader { +pub struct SystemReader { pub(crate) expanding_reader: ExpandingReader, } @@ -122,7 +122,7 @@ impl SystemTextReader_1_1 { } } -impl SystemReader { +impl SystemReader { // Returns `true` if the provided [`LazyRawValue`] is a struct whose first annotation is // `$ion_symbol_table`. pub fn is_symbol_table_struct( diff --git a/src/lazy/system_stream_item.rs b/src/lazy/system_stream_item.rs index 70415b18..f70b1e2c 100644 --- a/src/lazy/system_stream_item.rs +++ b/src/lazy/system_stream_item.rs @@ -1,6 +1,6 @@ use std::fmt::{Debug, Formatter}; -use crate::lazy::decoder::{LazyDecoder, RawVersionMarker}; +use crate::lazy::decoder::{Decoder, RawVersionMarker}; use crate::lazy::expanded::ExpandedValueSource; use crate::lazy::r#struct::LazyStruct; use crate::lazy::raw_stream_item::{EndPosition, LazyRawStreamItem, RawStreamItem}; @@ -10,7 +10,7 @@ use crate::{IonError, IonResult}; /// System stream elements that a SystemReader may encounter. #[non_exhaustive] -pub enum SystemStreamItem<'top, D: LazyDecoder> { +pub enum SystemStreamItem<'top, D: Decoder> { /// An Ion Version Marker (IVM) indicating the Ion major and minor version that were used to /// encode the values that follow. VersionMarker(D::VersionMarker<'top>), @@ -22,7 +22,7 @@ pub enum SystemStreamItem<'top, D: LazyDecoder> { EndOfStream(EndPosition), } -impl<'top, D: LazyDecoder> Debug for SystemStreamItem<'top, D> { +impl<'top, D: Decoder> Debug for SystemStreamItem<'top, D> { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { match self { SystemStreamItem::VersionMarker(marker) => { @@ -35,7 +35,7 @@ impl<'top, D: LazyDecoder> Debug for SystemStreamItem<'top, D> { } } -impl<'top, D: LazyDecoder> SystemStreamItem<'top, D> { +impl<'top, D: Decoder> SystemStreamItem<'top, D> { /// If this item is an Ion version marker (IVM), returns `Some(version_marker)` indicating the /// version. Otherwise, returns `None`. pub fn version_marker(&self) -> Option> { diff --git a/src/lazy/text/matched.rs b/src/lazy/text/matched.rs index 076c03ed..0ade70d5 100644 --- a/src/lazy/text/matched.rs +++ b/src/lazy/text/matched.rs @@ -36,7 +36,7 @@ use smallvec::SmallVec; use crate::decimal::coefficient::Coefficient; use crate::lazy::bytes_ref::BytesRef; -use crate::lazy::decoder::{LazyDecoder, LazyRawFieldExpr, LazyRawValueExpr}; +use crate::lazy::decoder::{Decoder, LazyRawFieldExpr, LazyRawValueExpr}; use crate::lazy::span::Span; use crate::lazy::str_ref::StrRef; use crate::lazy::text::as_utf8::AsUtf8; @@ -49,7 +49,7 @@ use crate::{ /// A partially parsed Ion value. #[derive(Clone, Copy, Debug)] -pub enum MatchedValue<'top, D: LazyDecoder> { +pub enum MatchedValue<'top, D: Decoder> { // `Null` and `Bool` are fully parsed because they only involve matching a keyword. Null(IonType), Bool(bool), @@ -66,7 +66,7 @@ pub enum MatchedValue<'top, D: LazyDecoder> { Struct(&'top [LazyRawFieldExpr<'top, D>]), } -impl<'top, D: LazyDecoder> PartialEq for MatchedValue<'top, D> { +impl<'top, D: Decoder> PartialEq for MatchedValue<'top, D> { fn eq(&self, other: &Self) -> bool { use MatchedValue::*; match (self, other) { diff --git a/src/lazy/text/raw/reader.rs b/src/lazy/text/raw/reader.rs index 11735d43..88c7c54c 100644 --- a/src/lazy/text/raw/reader.rs +++ b/src/lazy/text/raw/reader.rs @@ -2,7 +2,7 @@ use bumpalo::Bump as BumpAllocator; -use crate::lazy::decoder::{LazyDecoder, LazyRawReader, RawVersionMarker}; +use crate::lazy::decoder::{Decoder, LazyRawReader, RawVersionMarker}; use crate::lazy::encoding::TextEncoding_1_0; use crate::lazy::raw_stream_item::{EndPosition, LazyRawStreamItem, RawStreamItem}; use crate::lazy::text::buffer::TextBufferView; @@ -89,7 +89,7 @@ impl<'data> LazyRawReader<'data, TextEncoding_1_0> for LazyRawTextReader_1_0<'da fn resume_at_offset( data: &'data [u8], offset: usize, - _config: ::ReaderSavedState, + _config: ::ReaderSavedState, ) -> Self { LazyRawTextReader_1_0::new_with_offset(data, offset) } diff --git a/src/lazy/text/raw/sequence.rs b/src/lazy/text/raw/sequence.rs index 3ac46d11..1187e77b 100644 --- a/src/lazy/text/raw/sequence.rs +++ b/src/lazy/text/raw/sequence.rs @@ -7,7 +7,7 @@ use nom::character::streaming::satisfy; use crate::lazy::decoder::private::LazyContainerPrivate; use crate::lazy::decoder::{ - LazyDecoder, LazyRawContainer, LazyRawSequence, LazyRawValue, LazyRawValueExpr, RawValueExpr, + Decoder, LazyRawContainer, LazyRawSequence, LazyRawValue, LazyRawValueExpr, RawValueExpr, }; use crate::lazy::encoding::TextEncoding_1_0; use crate::lazy::text::buffer::TextBufferView; @@ -43,7 +43,7 @@ impl<'data> LazyContainerPrivate<'data, TextEncoding_1_0> for LazyRawTextList_1_ } impl<'data> LazyRawContainer<'data, TextEncoding_1_0> for LazyRawTextList_1_0<'data> { - fn as_value(&self) -> ::Value<'data> { + fn as_value(&self) -> ::Value<'data> { self.value } } @@ -255,7 +255,7 @@ impl<'data> LazyContainerPrivate<'data, TextEncoding_1_0> for LazyRawTextSExp_1_ } impl<'data> LazyRawContainer<'data, TextEncoding_1_0> for LazyRawTextSExp_1_0<'data> { - fn as_value(&self) -> ::Value<'data> { + fn as_value(&self) -> ::Value<'data> { self.value } } diff --git a/src/lazy/text/raw/struct.rs b/src/lazy/text/raw/struct.rs index b806bb5f..8e9e29af 100644 --- a/src/lazy/text/raw/struct.rs +++ b/src/lazy/text/raw/struct.rs @@ -6,7 +6,7 @@ use nom::character::streaming::satisfy; use crate::lazy::decoder::private::LazyContainerPrivate; use crate::lazy::decoder::{ - HasRange, HasSpan, LazyDecoder, LazyRawContainer, LazyRawFieldExpr, LazyRawFieldName, + Decoder, HasRange, HasSpan, LazyRawContainer, LazyRawFieldExpr, LazyRawFieldName, LazyRawStruct, LazyRawValue, }; use crate::lazy::encoding::TextEncoding_1_0; @@ -124,7 +124,7 @@ impl<'top> LazyContainerPrivate<'top, TextEncoding_1_0> for LazyRawTextStruct_1_ } impl<'top> LazyRawContainer<'top, TextEncoding_1_0> for LazyRawTextStruct_1_0<'top> { - fn as_value(&self) -> ::Value<'top> { + fn as_value(&self) -> ::Value<'top> { self.value } } diff --git a/src/lazy/text/raw/v1_1/reader.rs b/src/lazy/text/raw/v1_1/reader.rs index e1cdf4bf..4a8fbe91 100644 --- a/src/lazy/text/raw/v1_1/reader.rs +++ b/src/lazy/text/raw/v1_1/reader.rs @@ -10,7 +10,7 @@ use nom::character::streaming::satisfy; use crate::lazy::decoder::private::LazyContainerPrivate; use crate::lazy::decoder::{ - HasRange, HasSpan, LazyDecoder, LazyRawContainer, LazyRawFieldExpr, LazyRawFieldName, + Decoder, HasRange, HasSpan, LazyRawContainer, LazyRawFieldExpr, LazyRawFieldName, LazyRawReader, LazyRawSequence, LazyRawStruct, LazyRawValue, LazyRawValueExpr, RawVersionMarker, }; @@ -138,7 +138,7 @@ impl<'data> LazyRawReader<'data, TextEncoding_1_1> for LazyRawTextReader_1_1<'da fn resume_at_offset( data: &'data [u8], offset: usize, - _config: ::ReaderSavedState, + _config: ::ReaderSavedState, ) -> Self { LazyRawTextReader_1_1 { input: data, @@ -414,7 +414,7 @@ impl<'top> LazyContainerPrivate<'top, TextEncoding_1_1> for LazyRawTextSExp_1_1< } impl<'top> LazyRawContainer<'top, TextEncoding_1_1> for LazyRawTextSExp_1_1<'top> { - fn as_value(&self) -> ::Value<'top> { + fn as_value(&self) -> ::Value<'top> { self.value } } @@ -624,7 +624,7 @@ impl<'top> LazyContainerPrivate<'top, TextEncoding_1_1> for LazyRawTextStruct_1_ } impl<'top> LazyRawContainer<'top, TextEncoding_1_1> for LazyRawTextStruct_1_1<'top> { - fn as_value(&self) -> ::Value<'top> { + fn as_value(&self) -> ::Value<'top> { self.value } } diff --git a/src/lazy/text/value.rs b/src/lazy/text/value.rs index 42742265..faaa2153 100644 --- a/src/lazy/text/value.rs +++ b/src/lazy/text/value.rs @@ -6,7 +6,7 @@ use std::marker::PhantomData; use std::ops::Range; use crate::lazy::decoder::private::LazyContainerPrivate; -use crate::lazy::decoder::{HasRange, HasSpan, LazyDecoder, LazyRawValue, RawVersionMarker}; +use crate::lazy::decoder::{Decoder, HasRange, HasSpan, LazyRawValue, RawVersionMarker}; use crate::lazy::encoding::{TextEncoding, TextEncoding_1_0, TextEncoding_1_1}; use crate::lazy::raw_value_ref::RawValueRef; use crate::lazy::span::Span; @@ -178,7 +178,7 @@ impl<'top, E: TextEncoding<'top>> LazyRawValue<'top, E> for LazyRawTextValue<'to self.encoded_value.is_null() } - fn annotations(&self) -> ::AnnotationsIterator<'top> { + fn annotations(&self) -> ::AnnotationsIterator<'top> { let range = self .encoded_value .annotations_range() diff --git a/src/lazy/value.rs b/src/lazy/value.rs index 1e42b578..37fb99b9 100644 --- a/src/lazy/value.rs +++ b/src/lazy/value.rs @@ -1,4 +1,4 @@ -use crate::lazy::decoder::LazyDecoder; +use crate::lazy::decoder::Decoder; use crate::lazy::encoding::BinaryEncoding_1_0; use crate::lazy::expanded::{ExpandedAnnotationsIterator, ExpandedValueRef, LazyExpandedValue}; use crate::lazy::r#struct::LazyStruct; @@ -55,13 +55,13 @@ use crate::{ ///# fn main() -> IonResult<()> { Ok(()) } /// ``` #[derive(Copy, Clone)] -pub struct LazyValue<'top, D: LazyDecoder> { +pub struct LazyValue<'top, D: Decoder> { pub(crate) expanded_value: LazyExpandedValue<'top, D>, } pub type LazyBinaryValue<'top> = LazyValue<'top, BinaryEncoding_1_0>; -impl<'top, D: LazyDecoder> LazyValue<'top, D> { +impl<'top, D: Decoder> LazyValue<'top, D> { pub(crate) fn new(expanded_value: LazyExpandedValue<'top, D>) -> LazyValue<'top, D> { LazyValue { expanded_value } } @@ -273,7 +273,7 @@ impl<'top, D: LazyDecoder> LazyValue<'top, D> { } } -impl<'top, D: LazyDecoder> TryFrom> for Element { +impl<'top, D: Decoder> TryFrom> for Element { type Error = IonError; fn try_from(value: LazyValue<'top, D>) -> Result { @@ -285,12 +285,12 @@ impl<'top, D: LazyDecoder> TryFrom> for Element { /// Iterates over a slice of bytes, lazily reading them as a sequence of symbol tokens encoded /// using the format described by generic type parameter `D`. -pub struct AnnotationsIterator<'top, D: LazyDecoder> { +pub struct AnnotationsIterator<'top, D: Decoder> { pub(crate) expanded_annotations: ExpandedAnnotationsIterator<'top, D>, pub(crate) symbol_table: &'top SymbolTable, } -impl<'top, D: LazyDecoder> AnnotationsIterator<'top, D> { +impl<'top, D: Decoder> AnnotationsIterator<'top, D> { /// Returns `Ok(true)` if this annotations iterator matches the provided sequence exactly, or /// `Ok(false)` if not. If a decoding error occurs while visiting and resolving each annotation, /// returns an `Err(IonError)`. @@ -379,7 +379,7 @@ impl<'top, D: LazyDecoder> AnnotationsIterator<'top, D> { } } -impl<'top, D: LazyDecoder> Iterator for AnnotationsIterator<'top, D> { +impl<'top, D: Decoder> Iterator for AnnotationsIterator<'top, D> { type Item = IonResult>; fn next(&mut self) -> Option { @@ -397,7 +397,7 @@ impl<'top, D: LazyDecoder> Iterator for AnnotationsIterator<'top, D> { } } -impl<'top, D: LazyDecoder> TryFrom> for Annotations { +impl<'top, D: Decoder> TryFrom> for Annotations { type Error = IonError; fn try_from(iter: AnnotationsIterator<'top, D>) -> Result { diff --git a/src/lazy/value_ref.rs b/src/lazy/value_ref.rs index 74306957..73722c60 100644 --- a/src/lazy/value_ref.rs +++ b/src/lazy/value_ref.rs @@ -1,6 +1,6 @@ use crate::element::Value; use crate::lazy::bytes_ref::BytesRef; -use crate::lazy::decoder::LazyDecoder; +use crate::lazy::decoder::Decoder; use crate::lazy::r#struct::LazyStruct; use crate::lazy::sequence::{LazyList, LazySExp}; use crate::lazy::str_ref::StrRef; @@ -16,7 +16,7 @@ use std::fmt::{Debug, Formatter}; /// to existing resources. Numeric values and timestamps are stored within the `ValueRef` itself. /// Text values and lobs hold references to either a slice of input data or text in the symbol table. #[derive(Copy, Clone)] -pub enum ValueRef<'top, D: LazyDecoder> { +pub enum ValueRef<'top, D: Decoder> { Null(IonType), Bool(bool), Int(Int), @@ -32,7 +32,7 @@ pub enum ValueRef<'top, D: LazyDecoder> { Struct(LazyStruct<'top, D>), } -impl<'top, D: LazyDecoder> PartialEq for ValueRef<'top, D> { +impl<'top, D: Decoder> PartialEq for ValueRef<'top, D> { fn eq(&self, other: &Self) -> bool { use ValueRef::*; match (self, other) { @@ -55,7 +55,7 @@ impl<'top, D: LazyDecoder> PartialEq for ValueRef<'top, D> { } } -impl<'top, D: LazyDecoder> Debug for ValueRef<'top, D> { +impl<'top, D: Decoder> Debug for ValueRef<'top, D> { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { use ValueRef::*; match self { @@ -76,7 +76,7 @@ impl<'top, D: LazyDecoder> Debug for ValueRef<'top, D> { } } -impl<'top, D: LazyDecoder> TryFrom> for Value { +impl<'top, D: Decoder> TryFrom> for Value { type Error = IonError; fn try_from(value: ValueRef<'top, D>) -> Result { @@ -100,7 +100,7 @@ impl<'top, D: LazyDecoder> TryFrom> for Value { } } -impl<'top, D: LazyDecoder> TryFrom> for Element { +impl<'top, D: Decoder> TryFrom> for Element { type Error = IonError; fn try_from(value_ref: ValueRef<'top, D>) -> Result { @@ -109,7 +109,7 @@ impl<'top, D: LazyDecoder> TryFrom> for Element { } } -impl<'top, D: LazyDecoder> ValueRef<'top, D> { +impl<'top, D: Decoder> ValueRef<'top, D> { pub fn expect_null(self) -> IonResult { if let ValueRef::Null(ion_type) = self { Ok(ion_type) diff --git a/src/lib.rs b/src/lib.rs index fba638c1..1c4f9eaa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -199,8 +199,8 @@ macro_rules! v1_x_reader_writer { #[allow(unused_imports)] $visibility use crate::{ lazy::streaming_raw_reader::{IonInput, IonSlice, IonStream}, - lazy::decoder::LazyDecoder, - lazy::encoder::LazyEncoder, + lazy::decoder::Decoder, + lazy::encoder::Encoder, lazy::encoding::Encoding, lazy::encoder::annotate::Annotatable, lazy::encoder::write_as_ion::WriteAsIon, diff --git a/src/serde/de.rs b/src/serde/de.rs index 7e110da1..6bccd94b 100644 --- a/src/serde/de.rs +++ b/src/serde/de.rs @@ -19,7 +19,7 @@ where T: DeserializeOwned, I: IonInput, { - let mut reader = Reader::new(input); + let mut reader = Reader::new(input)?; let value = reader.expect_next()?; let value_deserializer = ValueDeserializer::new(&value); T::deserialize(value_deserializer) diff --git a/src/serde/ser.rs b/src/serde/ser.rs index eee478a9..11066419 100644 --- a/src/serde/ser.rs +++ b/src/serde/ser.rs @@ -7,7 +7,7 @@ use serde::{ser, Serialize}; use crate::lazy::encoder::value_writer::internal::{FieldEncoder, MakeValueWriter}; use crate::lazy::encoder::value_writer::{SequenceWriter, StructWriter, ValueWriter}; -use crate::lazy::encoder::writer::IonWriter; +use crate::lazy::encoder::writer::Writer; use crate::lazy::encoding::{BinaryEncoding_1_0, Encoding, TextEncoding_1_0}; use crate::result::IonFailure; use crate::serde::decimal::TUNNELED_DECIMAL_TYPE_NAME; @@ -19,7 +19,7 @@ use crate::{Decimal, IonError, IonResult, IonType, TextFormat, Timestamp}; pub fn write_to( value: &T, - writer: &mut IonWriter, + writer: &mut Writer, ) -> IonResult<()> { let serializer = ValueSerializer::new(writer.value_writer()); value.serialize(serializer) @@ -29,7 +29,7 @@ fn write_with_config( value: &T, config: WriteConfig, ) -> IonResult> { - let mut writer = IonWriter::with_config(config, vec![])?; + let mut writer = Writer::with_config(config, vec![])?; write_to(value, &mut writer)?; writer.close() } diff --git a/src/write_config.rs b/src/write_config.rs index 1f2f9278..09d195c1 100644 --- a/src/write_config.rs +++ b/src/write_config.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; use crate::lazy::encoder::value_writer::SequenceWriter; use crate::lazy::encoder::write_as_ion::WriteAsIon; -use crate::lazy::encoder::writer::IonWriter; +use crate::lazy::encoder::writer::Writer; use crate::lazy::encoder::LazyRawWriter; use crate::lazy::encoding::{ BinaryEncoding_1_0, BinaryEncoding_1_1, Encoding, OutputFromBytes, TextEncoding_1_0, @@ -38,7 +38,7 @@ impl WriteConfig { value: V, output: W, ) -> IonResult { - let mut writer = IonWriter::with_config(self.clone(), output)?; + let mut writer = Writer::with_config(self.clone(), output)?; writer.write(value)?; writer.close() } @@ -48,21 +48,21 @@ impl WriteConfig { output: W, values: I, ) -> IonResult { - let mut writer = IonWriter::with_config(self.clone(), output)?; + let mut writer = Writer::with_config(self.clone(), output)?; writer.write_all(values)?; writer.close() } #[cfg(feature = "experimental-reader-writer")] - pub fn build_writer(self, output: W) -> IonResult> { - IonWriter::with_config(self, output) + pub fn build_writer(self, output: W) -> IonResult> { + Writer::with_config(self, output) } // When the experimental-reader-writer feature is disabled, this method is `pub(crate)` instead // of `pub` #[cfg(not(feature = "experimental-reader-writer"))] - pub(crate) fn build_writer(self, output: W) -> IonResult> { - IonWriter::with_config(self, output) + pub(crate) fn build_writer(self, output: W) -> IonResult> { + Writer::with_config(self, output) } #[cfg(feature = "experimental-tooling-apis")] diff --git a/tests/ion_hash_tests.rs b/tests/ion_hash_tests.rs index 5b350d81..d0d18862 100644 --- a/tests/ion_hash_tests.rs +++ b/tests/ion_hash_tests.rs @@ -122,7 +122,7 @@ fn ion_hash_tests() -> IonHashTestResult<()> { fn test_file(file_name: &str) -> IonHashTestResult<()> { let data = read(file_name).map_err(IonError::from)?; - let mut reader = Reader::new(data); + let mut reader = Reader::new(data)?; let mut elems = Vec::new(); while let Some(value) = reader.next()? { // Similar logic to skip test cases with a name on the skip list also appears in the diff --git a/tests/ion_tests/mod.rs b/tests/ion_tests/mod.rs index 55323da1..a5c0a84b 100644 --- a/tests/ion_tests/mod.rs +++ b/tests/ion_tests/mod.rs @@ -7,7 +7,7 @@ use std::fs::read; use std::path::MAIN_SEPARATOR as PATH_SEPARATOR; use ion_rs::lazy::encoder::value_writer::SequenceWriter; -use ion_rs::lazy::encoder::writer::IonWriter; +use ion_rs::lazy::encoder::writer::Writer; use ion_rs::lazy::encoding::{BinaryEncoding_1_0, TextEncoding_1_0}; use ion_rs::WriteConfig; use ion_rs::{ @@ -52,7 +52,7 @@ pub fn serialize(format: Format, elements: &Sequence) -> IonResult> { match format { Format::Text(kind) => { let write_config = WriteConfig::::new(kind); - let mut writer = IonWriter::with_config(write_config, buffer)?; + let mut writer = Writer::with_config(write_config, buffer)?; writer.write_elements(elements)?; buffer = writer.close()?; println!( @@ -61,7 +61,7 @@ pub fn serialize(format: Format, elements: &Sequence) -> IonResult> { ); } Format::Binary => { - let mut binary_writer = IonWriter::::new(buffer)?; + let mut binary_writer = Writer::::new(buffer)?; binary_writer.write_elements(elements)?; buffer = binary_writer.close()?; }