diff --git a/benches/write_many_structs.rs b/benches/write_many_structs.rs index 8151b952..7268f758 100644 --- a/benches/write_many_structs.rs +++ b/benches/write_many_structs.rs @@ -93,8 +93,8 @@ fn write_eexp_with_symbol_values(value_writer: impl ValueWriter) -> IonResult<() .write(symbol_id(black_box(11)))? // $12 = "2022-12-07T20:59:59.744000Z" (string, not timestamp) .write(symbol_id(black_box(12)))?; - nested_eexp.end()?; - eexp.end() + nested_eexp.close()?; + eexp.close() } fn write_eexp_with_string_values(value_writer: impl ValueWriter) -> IonResult<()> { @@ -108,8 +108,8 @@ fn write_eexp_with_string_values(value_writer: impl ValueWriter) -> IonResult<() nested_eexp .write(black_box("region 4"))? .write(black_box("2022-12-07T20:59:59.744000Z"))?; - nested_eexp.end()?; - eexp.end() + nested_eexp.close()?; + eexp.close() } fn symbol_id(sid: usize) -> RawSymbolTokenRef<'static> { diff --git a/examples/write_log_events.rs b/examples/write_log_events.rs index aacbb251..c9dd627c 100644 --- a/examples/write_log_events.rs +++ b/examples/write_log_events.rs @@ -214,7 +214,7 @@ mod example { eexp // Ignore the part of the thread name that starts with the recurring prefix. .write(&self.0[THREAD_NAME_PREFIX.len()..])?; - eexp.end() + eexp.close() } } @@ -227,7 +227,7 @@ mod example { // Wrap the thread name in the `ThreadName` wrapper to change its serialization. .write(ThreadName(&event.thread_name))? .write(&event.parameters)?; - eexp.end() + eexp.close() } } diff --git a/src/lazy/encoder/binary/v1_0/container_writers.rs b/src/lazy/encoder/binary/v1_0/container_writers.rs index 7836b9f7..8687abcf 100644 --- a/src/lazy/encoder/binary/v1_0/container_writers.rs +++ b/src/lazy/encoder/binary/v1_0/container_writers.rs @@ -208,9 +208,9 @@ impl<'value, 'top> MakeValueWriter for BinaryListWriter_1_0<'value, 'top> { } impl<'value, 'top> SequenceWriter for BinaryListWriter_1_0<'value, 'top> { - type End = (); + type Resources = (); - fn end(self) -> IonResult { + fn close(self) -> IonResult { self.container_writer.end() } } @@ -227,9 +227,9 @@ impl<'value, 'top> MakeValueWriter for BinarySExpWriter_1_0<'value, 'top> { } impl<'value, 'top> SequenceWriter for BinarySExpWriter_1_0<'value, 'top> { - type End = (); + type Resources = (); - fn end(self) -> IonResult { + fn close(self) -> IonResult { self.container_writer.end() } } diff --git a/src/lazy/encoder/binary/v1_0/value_writer.rs b/src/lazy/encoder/binary/v1_0/value_writer.rs index 9f449a85..65934c42 100644 --- a/src/lazy/encoder/binary/v1_0/value_writer.rs +++ b/src/lazy/encoder/binary/v1_0/value_writer.rs @@ -465,7 +465,7 @@ mod tests { let expected = Element::read_all(expected)?; let mut writer = LazyRawBinaryWriter_1_0::new(Vec::new())?; test(&mut writer)?; - let buffer = writer.finish()?; + let buffer = writer.close()?; let actual = Element::read_all(buffer)?; assert!( IonData::eq(&expected, &actual), @@ -502,7 +502,7 @@ mod tests { #[test] fn write_empty_list() -> IonResult<()> { let expected = "[]"; - writer_test(expected, |writer| writer.list_writer()?.end()) + writer_test(expected, |writer| writer.list_writer()?.close()) } #[test] @@ -530,14 +530,14 @@ mod tests { .write(Timestamp::with_ymd(2023, 11, 9).build()?)? .write([0xE0u8, 0x01, 0x00, 0xEA])? .write([1, 2, 3])?; - list.end() + list.close() }) } #[test] fn write_empty_sexp() -> IonResult<()> { let expected = "()"; - writer_test(expected, |writer| writer.sexp_writer()?.end()) + writer_test(expected, |writer| writer.sexp_writer()?.close()) } #[test] @@ -565,7 +565,7 @@ mod tests { .write(Timestamp::with_ymd(2023, 11, 9).build()?)? .write([0xE0u8, 0x01, 0x00, 0xEA])? .write([1, 2, 3])?; - sexp.end() + sexp.close() }) } diff --git a/src/lazy/encoder/binary/v1_0/writer.rs b/src/lazy/encoder/binary/v1_0/writer.rs index 64e7a768..54178ea6 100644 --- a/src/lazy/encoder/binary/v1_0/writer.rs +++ b/src/lazy/encoder/binary/v1_0/writer.rs @@ -84,11 +84,6 @@ impl LazyRawBinaryWriter_1_0 { Ok(()) } - pub fn finish(mut self) -> IonResult { - self.flush()?; - Ok(self.output) - } - pub(crate) fn value_writer(&mut self) -> BinaryValueWriter_1_0<'_, '_> { let top_level = match self.encoding_buffer_ptr { // If the `encoding_buffer_ptr` is set, we already allocated an encoding buffer on @@ -129,7 +124,6 @@ impl LazyRawWriter for LazyRawBinaryWriter_1_0 { delegate! { to self { fn flush(&mut self) -> IonResult<()>; - fn finish(self) -> IonResult; } } } @@ -143,10 +137,11 @@ impl MakeValueWriter for LazyRawBinaryWriter_1_0 { } impl SequenceWriter for LazyRawBinaryWriter_1_0 { - type End = W; + type Resources = W; - fn end(self) -> IonResult { - self.finish() + fn close(mut self) -> IonResult { + self.flush()?; + Ok(self.output) } // Uses the default method implementations from SequenceWriter } diff --git a/src/lazy/encoder/binary/v1_1/container_writers.rs b/src/lazy/encoder/binary/v1_1/container_writers.rs index f06dce2e..590ca1c2 100644 --- a/src/lazy/encoder/binary/v1_1/container_writers.rs +++ b/src/lazy/encoder/binary/v1_1/container_writers.rs @@ -188,14 +188,14 @@ impl<'value, 'top> MakeValueWriter for BinaryListWriter_1_1<'value, 'top> { } impl<'value, 'top> SequenceWriter for BinaryListWriter_1_1<'value, 'top> { - type End = (); + type Resources = (); fn write(&mut self, value: V) -> IonResult<&mut Self> { self.container_writer.write(value)?; Ok(self) } - fn end(self) -> IonResult { + fn close(self) -> IonResult { self.container_writer.end() } } @@ -251,14 +251,14 @@ impl<'value, 'top> MakeValueWriter for BinarySExpWriter_1_1<'value, 'top> { } impl<'value, 'top> SequenceWriter for BinarySExpWriter_1_1<'value, 'top> { - type End = (); + type Resources = (); fn write(&mut self, value: V) -> IonResult<&mut Self> { self.container_writer.write(value)?; Ok(self) } - fn end(self) -> IonResult { + fn close(self) -> IonResult { self.container_writer.end() } } @@ -383,9 +383,9 @@ impl<'value, 'top> MakeValueWriter for BinaryEExpWriter_1_1<'value, 'top> { } impl<'value, 'top> SequenceWriter for BinaryEExpWriter_1_1<'value, 'top> { - type End = (); + type Resources = (); - fn end(self) -> IonResult { + fn close(self) -> IonResult { // Nothing to do // TODO: When we have length-prefixed macro invocations, this will require a step to flush the buffered encoding. Ok(()) diff --git a/src/lazy/encoder/binary/v1_1/value_writer.rs b/src/lazy/encoder/binary/v1_1/value_writer.rs index 8d48f49c..01f3eb9d 100644 --- a/src/lazy/encoder/binary/v1_1/value_writer.rs +++ b/src/lazy/encoder/binary/v1_1/value_writer.rs @@ -2224,7 +2224,7 @@ mod tests { .with_delimited_containers() .list_writer()?; list.write_all(*value)?; - list.end() + list.close() }, expected_encoding, )?; @@ -2323,7 +2323,7 @@ mod tests { .with_delimited_containers() .sexp_writer()?; sexp.write_all(*value)?; - sexp.end() + sexp.close() }, expected_encoding, )?; @@ -2781,7 +2781,7 @@ mod tests { args.write_symbol("foo")? .write_symbol("bar")? .write_symbol("baz")?; - args.end() + args.close() }, &[ 0x00, // Invoke macro address 0 diff --git a/src/lazy/encoder/binary/v1_1/writer.rs b/src/lazy/encoder/binary/v1_1/writer.rs index e2f3dd91..38a70438 100644 --- a/src/lazy/encoder/binary/v1_1/writer.rs +++ b/src/lazy/encoder/binary/v1_1/writer.rs @@ -84,11 +84,6 @@ impl LazyRawBinaryWriter_1_1 { Ok(()) } - pub fn finish(mut self) -> IonResult { - self.flush()?; - Ok(self.output) - } - // All methods called on the writer are inherently happening at the top level. At the top level, // the lifetimes `'value` and `'top` are identical. In this method signature, '_ is used for both. pub(crate) fn value_writer(&mut self) -> BinaryValueWriter_1_1<'_, '_> { @@ -140,7 +135,6 @@ impl LazyRawWriter for LazyRawBinaryWriter_1_1 { delegate! { to self { fn flush(&mut self) -> IonResult<()>; - fn finish(self) -> IonResult; } } } @@ -154,10 +148,10 @@ impl MakeValueWriter for LazyRawBinaryWriter_1_1 { } impl SequenceWriter for LazyRawBinaryWriter_1_1 { - type End = W; + type Resources = W; - fn end(self) -> IonResult { - // Ending the top-level sequence is the same as calling `finish` on the writer itself. - self.finish() + fn close(mut self) -> IonResult { + self.flush()?; + Ok(self.output) } } diff --git a/src/lazy/encoder/mod.rs b/src/lazy/encoder/mod.rs index 30746ea4..fd252305 100644 --- a/src/lazy/encoder/mod.rs +++ b/src/lazy/encoder/mod.rs @@ -37,7 +37,7 @@ pub(crate) mod private { } /// An Ion writer without an encoding context (that is: symbol/macro tables). -pub trait LazyRawWriter: SequenceWriter { +pub trait LazyRawWriter: SequenceWriter { fn new(output: W) -> IonResult where Self: Sized; @@ -45,8 +45,6 @@ pub trait LazyRawWriter: SequenceWriter { where Self: Sized; fn flush(&mut self) -> IonResult<()>; - - fn finish(self) -> IonResult; } #[cfg(test)] diff --git a/src/lazy/encoder/text/mod.rs b/src/lazy/encoder/text/mod.rs index dd0889e4..07319c2d 100644 --- a/src/lazy/encoder/text/mod.rs +++ b/src/lazy/encoder/text/mod.rs @@ -44,11 +44,6 @@ impl LazyRawTextWriter_1_0 { Ok(()) } - pub fn finish(mut self) -> IonResult { - self.flush()?; - Ok(self.output) - } - /// Helper method to construct this format's `ValueWriter` implementation. #[inline] fn value_writer(&mut self) -> TextValueWriter_1_0<'_, W> { @@ -61,11 +56,11 @@ impl LazyRawTextWriter_1_0 { } impl SequenceWriter for LazyRawTextWriter_1_0 { - type End = W; + type Resources = W; - fn end(self) -> IonResult { - // Calling `end()` on the top level sequence is the same as calling `finish()` on the writer. - self.finish() + fn close(mut self) -> IonResult { + self.flush()?; + Ok(self.output) } } @@ -99,7 +94,6 @@ impl LazyRawWriter for LazyRawTextWriter_1_0 { delegate! { to self { fn flush(&mut self) -> IonResult<()>; - fn finish(self) -> IonResult; } } } diff --git a/src/lazy/encoder/text/value_writer.rs b/src/lazy/encoder/text/value_writer.rs index b7148100..32482004 100644 --- a/src/lazy/encoder/text/value_writer.rs +++ b/src/lazy/encoder/text/value_writer.rs @@ -225,13 +225,13 @@ impl<'top, W: Write> MakeValueWriter for TextListWriter_1_0<'top, W> { } impl<'top, W: Write> SequenceWriter for TextListWriter_1_0<'top, W> { - type End = (); + type Resources = (); fn write(&mut self, value: V) -> IonResult<&mut Self> { self.write(value) } - fn end(self) -> IonResult { + fn close(self) -> IonResult { self.end() } } @@ -270,7 +270,7 @@ impl<'value, W: Write> MakeValueWriter for TextSExpWriter_1_0<'value, W> { } impl<'a, W: Write> SequenceWriter for TextSExpWriter_1_0<'a, W> { - type End = (); + type Resources = (); delegate! { to self { @@ -278,7 +278,7 @@ impl<'a, W: Write> SequenceWriter for TextSExpWriter_1_0<'a, W> { } } - fn end(self) -> IonResult { + fn close(self) -> IonResult { self.end() } } diff --git a/src/lazy/encoder/value_writer.rs b/src/lazy/encoder/value_writer.rs index 8e0bb6e3..7f7990ac 100644 --- a/src/lazy/encoder/value_writer.rs +++ b/src/lazy/encoder/value_writer.rs @@ -38,10 +38,10 @@ pub trait ValueWriter: Sized { type AnnotatedValueWriter<'a, SymbolType: AsRawSymbolTokenRef + 'a>: ValueWriter where Self: 'a; - type ListWriter: SequenceWriter; - type SExpWriter: SequenceWriter; + type ListWriter: SequenceWriter; + type SExpWriter: SequenceWriter; type StructWriter: StructWriter; - type EExpWriter: EExpWriter; + type EExpWriter: EExpWriter; fn write_null(self, ion_type: IonType) -> IonResult<()>; fn write_bool(self, value: bool) -> IonResult<()>; @@ -75,13 +75,13 @@ pub trait ValueWriter: Sized { fn write_list>(self, values: I) -> IonResult<()> { let mut list = self.list_writer()?; list.write_all(values)?; - list.end() + list.close() } fn write_sexp>(self, values: I) -> IonResult<()> { let mut sexp = self.sexp_writer()?; sexp.write_all(values)?; - sexp.end() + sexp.close() } fn write_struct>( @@ -300,7 +300,7 @@ macro_rules! delegate_and_return_self { } pub trait SequenceWriter: MakeValueWriter { - /// The type returned by the [`end`](Self::end) method. + /// The type returned by the [`end`](Self::close) method. /// /// For top-level writers, this can be any resource(s) owned by the writer that need to survive /// after the writer is dropped. (For example, a `BufWriter` or `Vec` serving as the output.) @@ -308,7 +308,7 @@ pub trait SequenceWriter: MakeValueWriter { /// Containers and E-expressions must use `()`. // ^^^ This constraint could be loosened if needed, but it requires using verbose references // to `::End` in a variety of APIs. - type End; + type Resources; fn value_writer(&mut self) -> Self::ValueWriter<'_> { ::make_value_writer(self) @@ -334,7 +334,7 @@ pub trait SequenceWriter: MakeValueWriter { /// Closes out the sequence being written. Delimited writers can use this opportunity to emit /// a sentinel value, and length-prefixed writers can flush any buffered data to the output /// buffer. - fn end(self) -> IonResult; + fn close(self) -> IonResult; // Creates functions that delegate to the ValueWriter method of the same name but which then // return `self` so it can be re-used/chained. diff --git a/src/lazy/never.rs b/src/lazy/never.rs index 7b6d3aab..c30ef942 100644 --- a/src/lazy/never.rs +++ b/src/lazy/never.rs @@ -37,9 +37,9 @@ impl<'top, D: LazyDecoder> From for MacroExpr<'top, D> { } impl SequenceWriter for Never { - type End = (); + type Resources = (); - fn end(self) -> IonResult<()> { + fn close(self) -> IonResult<()> { unreachable!("SequenceWriter::end() in Never") } }