Skip to content

Commit

Permalink
Merge branch 'main' into feat-owned-conversion-qol
Browse files Browse the repository at this point in the history
  • Loading branch information
zslayton authored Dec 3, 2024
2 parents 5deb22d + f3b6cca commit dfcc720
Show file tree
Hide file tree
Showing 12 changed files with 240 additions and 123 deletions.
35 changes: 25 additions & 10 deletions src/lazy/encoder/binary/v1_0/container_writers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ use crate::lazy::encoder::value_writer::{SequenceWriter, StructWriter};
use crate::lazy::encoder::write_as_ion::WriteAsIon;
use crate::raw_symbol_ref::AsRawSymbolRef;
use crate::result::{EncodingError, IonFailure};
use crate::{v1_0, Encoding, IonError, IonResult, RawSymbolRef, SymbolId, ValueWriterConfig};
use crate::{
v1_0, ContextWriter, Encoding, IonError, IonResult, RawSymbolRef, SymbolId, ValueWriterConfig,
};

/// A helper type that holds fields and logic that is common to [`BinaryListWriter_1_0`],
/// [`BinarySExpWriter_1_0`], and [`BinaryStructWriter_1_0`].
Expand Down Expand Up @@ -197,10 +199,15 @@ impl<'value, 'top> BinaryListWriter_1_0<'value, 'top> {
}
}

impl<'top> MakeValueWriter for BinaryListWriter_1_0<'_, 'top> {
type ValueWriter<'a> = BinaryValueWriter_1_0<'a, 'top> where Self: 'a;
impl<'top> ContextWriter for BinaryListWriter_1_0<'_, 'top> {
type NestedValueWriter<'a>
= BinaryValueWriter_1_0<'a, 'top>
where
Self: 'a;
}

fn make_value_writer(&mut self) -> Self::ValueWriter<'_> {
impl MakeValueWriter for BinaryListWriter_1_0<'_, '_> {
fn make_value_writer(&mut self) -> Self::NestedValueWriter<'_> {
BinaryValueWriter_1_0::new(
self.container_writer.allocator,
&mut self.container_writer.child_values_buffer,
Expand All @@ -216,10 +223,15 @@ impl SequenceWriter for BinaryListWriter_1_0<'_, '_> {
}
}

impl<'top> MakeValueWriter for BinarySExpWriter_1_0<'_, 'top> {
type ValueWriter<'a> = BinaryValueWriter_1_0<'a, 'top> where Self: 'a;
impl<'top> ContextWriter for BinarySExpWriter_1_0<'_, 'top> {
type NestedValueWriter<'a>
= BinaryValueWriter_1_0<'a, 'top>
where
Self: 'a;
}

fn make_value_writer(&mut self) -> Self::ValueWriter<'_> {
impl MakeValueWriter for BinarySExpWriter_1_0<'_, '_> {
fn make_value_writer(&mut self) -> Self::NestedValueWriter<'_> {
BinaryValueWriter_1_0::new(
self.container_writer.allocator,
&mut self.container_writer.child_values_buffer,
Expand Down Expand Up @@ -322,12 +334,15 @@ impl FieldEncoder for BinaryStructWriter_1_0<'_, '_> {
}
}

impl<'top> MakeValueWriter for BinaryStructWriter_1_0<'_, 'top> {
type ValueWriter<'a> = BinaryValueWriter_1_0<'a, 'top>
impl<'top> ContextWriter for BinaryStructWriter_1_0<'_, 'top> {
type NestedValueWriter<'a>
= BinaryValueWriter_1_0<'a, 'top>
where
Self: 'a;
}

fn make_value_writer(&mut self) -> Self::ValueWriter<'_> {
impl MakeValueWriter for BinaryStructWriter_1_0<'_, '_> {
fn make_value_writer(&mut self) -> Self::NestedValueWriter<'_> {
BinaryValueWriter_1_0::new(
self.container_writer.allocator,
&mut self.container_writer.child_values_buffer,
Expand Down
13 changes: 9 additions & 4 deletions src/lazy/encoder/binary/v1_0/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::lazy::encoder::LazyRawWriter;
use crate::lazy::encoding::Encoding;
use crate::unsafe_helpers::{mut_ref_to_ptr, ptr_to_mut_ref, ptr_to_ref};
use crate::write_config::{WriteConfig, WriteConfigKind};
use crate::{IonEncoding, IonResult};
use crate::{ContextWriter, IonEncoding, IonResult};

/// A "raw"-level streaming binary Ion writer. This writer does not provide symbol table
/// management; symbol-related operations (e.g. setting field IDs and annotations or writing symbol
Expand Down Expand Up @@ -162,10 +162,15 @@ impl<W: Write> LazyRawWriter<W> for LazyRawBinaryWriter_1_0<W> {
}
}

impl<W: Write> MakeValueWriter for LazyRawBinaryWriter_1_0<W> {
type ValueWriter<'a> = BinaryValueWriter_1_0<'a, 'a> where Self: 'a;
impl<W: Write> ContextWriter for LazyRawBinaryWriter_1_0<W> {
type NestedValueWriter<'a>
= BinaryValueWriter_1_0<'a, 'a>
where
Self: 'a;
}

fn make_value_writer(&mut self) -> Self::ValueWriter<'_> {
impl<W: Write> MakeValueWriter for LazyRawBinaryWriter_1_0<W> {
fn make_value_writer(&mut self) -> Self::NestedValueWriter<'_> {
self.value_writer()
}
}
Expand Down
46 changes: 32 additions & 14 deletions src/lazy/encoder/binary/v1_1/container_writers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::lazy::encoder::value_writer::{EExpWriter, SequenceWriter, StructWrite
use crate::lazy::encoder::value_writer_config::ValueWriterConfig;
use crate::lazy::encoder::write_as_ion::WriteAsIon;
use crate::raw_symbol_ref::AsRawSymbolRef;
use crate::{v1_1, Encoding, IonResult, UInt};
use crate::{v1_1, ContextWriter, Encoding, IonResult, UInt};

/// A helper type that holds fields and logic that is common to [`BinaryListWriter_1_1`],
/// [`BinarySExpWriter_1_1`], and [`BinaryStructWriter_1_1`].
Expand Down Expand Up @@ -202,10 +202,15 @@ impl<'value, 'top> BinaryListWriter_1_1<'value, 'top> {
}
}

impl<'top> MakeValueWriter for BinaryListWriter_1_1<'_, 'top> {
type ValueWriter<'a> = BinaryValueWriter_1_1<'a, 'top> where Self: 'a;
impl<'top> ContextWriter for BinaryListWriter_1_1<'_, 'top> {
type NestedValueWriter<'a>
= BinaryValueWriter_1_1<'a, 'top>
where
Self: 'a;
}

fn make_value_writer(&mut self) -> Self::ValueWriter<'_> {
impl MakeValueWriter for BinaryListWriter_1_1<'_, '_> {
fn make_value_writer(&mut self) -> Self::NestedValueWriter<'_> {
self.container_writer.value_writer()
}
}
Expand Down Expand Up @@ -267,10 +272,15 @@ impl<'value, 'top> BinarySExpWriter_1_1<'value, 'top> {
}
}

impl<'top> MakeValueWriter for BinarySExpWriter_1_1<'_, 'top> {
type ValueWriter<'a> = BinaryValueWriter_1_1<'a, 'top> where Self: 'a;
impl<'top> ContextWriter for BinarySExpWriter_1_1<'_, 'top> {
type NestedValueWriter<'a>
= BinaryValueWriter_1_1<'a, 'top>
where
Self: 'a;
}

fn make_value_writer(&mut self) -> Self::ValueWriter<'_> {
impl MakeValueWriter for BinarySExpWriter_1_1<'_, '_> {
fn make_value_writer(&mut self) -> Self::NestedValueWriter<'_> {
let value_writer_config = self.container_writer.config();
BinaryValueWriter_1_1::new(
self.container_writer.allocator(),
Expand Down Expand Up @@ -373,12 +383,15 @@ impl FieldEncoder for BinaryStructWriter_1_1<'_, '_> {
}
}

impl<'top> MakeValueWriter for BinaryStructWriter_1_1<'_, 'top> {
type ValueWriter<'a> = BinaryValueWriter_1_1<'a, 'top>
impl<'top> ContextWriter for BinaryStructWriter_1_1<'_, 'top> {
type NestedValueWriter<'a>
= BinaryValueWriter_1_1<'a, 'top>
where
Self: 'a,;
Self: 'a;
}

fn make_value_writer(&mut self) -> Self::ValueWriter<'_> {
impl MakeValueWriter for BinaryStructWriter_1_1<'_, '_> {
fn make_value_writer(&mut self) -> Self::NestedValueWriter<'_> {
self.container_writer.value_writer()
}
}
Expand Down Expand Up @@ -418,10 +431,15 @@ impl<'value, 'top> BinaryEExpWriter_1_1<'value, 'top> {
}
}

impl<'top> MakeValueWriter for BinaryEExpWriter_1_1<'_, 'top> {
type ValueWriter<'a> = BinaryValueWriter_1_1<'a, 'top> where Self: 'a;
impl<'top> ContextWriter for BinaryEExpWriter_1_1<'_, 'top> {
type NestedValueWriter<'a>
= BinaryValueWriter_1_1<'a, 'top>
where
Self: 'a;
}

fn make_value_writer(&mut self) -> Self::ValueWriter<'_> {
impl MakeValueWriter for BinaryEExpWriter_1_1<'_, '_> {
fn make_value_writer(&mut self) -> Self::NestedValueWriter<'_> {
BinaryValueWriter_1_1::new(self.allocator, self.buffer, self.value_writer_config)
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/lazy/encoder/binary/v1_1/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::lazy::encoder::LazyRawWriter;
use crate::lazy::encoding::Encoding;
use crate::unsafe_helpers::{mut_ref_to_ptr, ptr_to_mut_ref, ptr_to_ref};
use crate::write_config::{WriteConfig, WriteConfigKind};
use crate::{IonEncoding, IonResult};
use crate::{ContextWriter, IonEncoding, IonResult};

/// A "raw"-level streaming binary Ion 1.1 writer. This writer does not provide encoding module
/// management; symbol- and macro- related operations require the caller to perform their own
Expand Down Expand Up @@ -162,13 +162,15 @@ impl<W: Write> LazyRawWriter<W> for LazyRawBinaryWriter_1_1<W> {
}
}

impl<W: Write> MakeValueWriter for LazyRawBinaryWriter_1_1<W> {
type ValueWriter<'a>
impl<W: Write> ContextWriter for LazyRawBinaryWriter_1_1<W> {
type NestedValueWriter<'a>
= BinaryValueWriter_1_1<'a, 'a>
where
Self: 'a;
}

fn make_value_writer(&mut self) -> Self::ValueWriter<'_> {
impl<W: Write> MakeValueWriter for LazyRawBinaryWriter_1_1<W> {
fn make_value_writer(&mut self) -> Self::NestedValueWriter<'_> {
self.value_writer()
}
}
Expand Down
44 changes: 32 additions & 12 deletions src/lazy/encoder/text/v1_0/value_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ use crate::text::text_formatter::{FmtValueFormatter, IoValueFormatter};
use crate::text::whitespace_config::WhitespaceConfig;
use crate::types::{ContainerType, ParentType};
use crate::{
v1_0, Decimal, Encoding, Int, IonResult, IonType, RawSymbolRef, Timestamp, ValueWriterConfig,
v1_0, ContextWriter, Decimal, Encoding, Int, IonResult, IonType, RawSymbolRef, Timestamp,
ValueWriterConfig,
};

pub struct TextValueWriter_1_0<'value, W: Write> {
Expand Down Expand Up @@ -296,10 +297,15 @@ impl<'top, W: Write> TextListWriter_1_0<'top, W> {
}
}

impl<W: Write> MakeValueWriter for TextListWriter_1_0<'_, W> {
type ValueWriter<'a> = TextValueWriter_1_0<'a, W> where Self: 'a;
impl<W: Write> ContextWriter for TextListWriter_1_0<'_, W> {
type NestedValueWriter<'a>
= TextValueWriter_1_0<'a, W>
where
Self: 'a;
}

fn make_value_writer(&mut self) -> Self::ValueWriter<'_> {
impl<W: Write> MakeValueWriter for TextListWriter_1_0<'_, W> {
fn make_value_writer(&mut self) -> Self::NestedValueWriter<'_> {
self.container_writer.value_writer()
}
}
Expand Down Expand Up @@ -353,10 +359,15 @@ impl<'a, W: Write> TextSExpWriter_1_0<'a, W> {
}
}

impl<W: Write> MakeValueWriter for TextSExpWriter_1_0<'_, W> {
type ValueWriter<'a> = TextValueWriter_1_0<'a, W> where Self: 'a;
impl<W: Write> ContextWriter for TextSExpWriter_1_0<'_, W> {
type NestedValueWriter<'a>
= TextValueWriter_1_0<'a, W>
where
Self: 'a;
}

fn make_value_writer(&mut self) -> Self::ValueWriter<'_> {
impl<W: Write> MakeValueWriter for TextSExpWriter_1_0<'_, W> {
fn make_value_writer(&mut self) -> Self::NestedValueWriter<'_> {
self.container_writer.value_writer()
}
}
Expand Down Expand Up @@ -422,12 +433,15 @@ impl<W: Write> FieldEncoder for TextStructWriter_1_0<'_, W> {
}
}

impl<W: Write> MakeValueWriter for TextStructWriter_1_0<'_, W> {
type ValueWriter<'a> = TextValueWriter_1_0<'a, W>
impl<W: Write> ContextWriter for TextStructWriter_1_0<'_, W> {
type NestedValueWriter<'a>
= TextValueWriter_1_0<'a, W>
where
Self: 'a;
}

fn make_value_writer(&mut self) -> Self::ValueWriter<'_> {
impl<W: Write> MakeValueWriter for TextStructWriter_1_0<'_, W> {
fn make_value_writer(&mut self) -> Self::NestedValueWriter<'_> {
TextValueWriter_1_0 {
writer: self.container_writer.writer,
depth: self.container_writer.depth + 1,
Expand All @@ -449,7 +463,10 @@ impl<W: Write> StructWriter for TextStructWriter_1_0<'_, W> {
}

impl<'value, W: Write + 'value> AnnotatableWriter for TextAnnotatedValueWriter_1_0<'value, W> {
type AnnotatedValueWriter<'a> = TextAnnotatedValueWriter_1_0<'a, W> where Self: 'a;
type AnnotatedValueWriter<'a>
= TextAnnotatedValueWriter_1_0<'a, W>
where
Self: 'a;

fn with_annotations<'a>(
self,
Expand Down Expand Up @@ -477,7 +494,10 @@ impl<'value, W: Write + 'value> ValueWriter for TextAnnotatedValueWriter_1_0<'va
}

impl<W: Write> AnnotatableWriter for TextValueWriter_1_0<'_, W> {
type AnnotatedValueWriter<'a> = TextAnnotatedValueWriter_1_0<'a, W> where Self: 'a;
type AnnotatedValueWriter<'a>
= TextAnnotatedValueWriter_1_0<'a, W>
where
Self: 'a;

fn with_annotations<'a>(
self,
Expand Down
11 changes: 7 additions & 4 deletions src/lazy/encoder/text/v1_0/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::text::whitespace_config::{
};
use crate::types::ParentType;
use crate::write_config::WriteConfigKind;
use crate::{IonEncoding, IonResult, TextFormat, WriteConfig};
use crate::{ContextWriter, IonEncoding, IonResult, TextFormat, WriteConfig};

/// A raw text Ion 1.0 writer.
pub struct LazyRawTextWriter_1_0<W: Write> {
Expand Down Expand Up @@ -60,12 +60,15 @@ impl<W: Write> SequenceWriter for LazyRawTextWriter_1_0<W> {
}
}

impl<W: Write> MakeValueWriter for LazyRawTextWriter_1_0<W> {
type ValueWriter<'a> = TextValueWriter_1_0<'a, W>
impl<W: Write> ContextWriter for LazyRawTextWriter_1_0<W> {
type NestedValueWriter<'a>
= TextValueWriter_1_0<'a, W>
where
Self: 'a;
}

fn make_value_writer(&mut self) -> Self::ValueWriter<'_> {
impl<W: Write> MakeValueWriter for LazyRawTextWriter_1_0<W> {
fn make_value_writer(&mut self) -> Self::NestedValueWriter<'_> {
self.value_writer()
}
}
Expand Down
Loading

0 comments on commit dfcc720

Please sign in to comment.