-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Binary 1.0 impl for new writer API #686
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3d893d0
Adds binary Ion 1.0 impl of the new writer API
zslayton 93c824a
Moved code into more cohesive modules
zslayton 9cce623
DRY via macros, some cleanup
zslayton aafd9b2
clippy suggestions
zslayton 0d0cabc
Added impl_write_as_ion_value! macro
zslayton d150ee1
removed old test code
zslayton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,15 @@ | ||
use crate::lazy::encoder::value_writer::AnnotatableValueWriter; | ||
use crate::lazy::encoder::write_as_ion::{WriteAsIon, WriteAsIonValue}; | ||
use crate::lazy::encoder::{AnnotatedValueWriter, LazyEncoder}; | ||
use crate::raw_symbol_token_ref::AsRawSymbolTokenRef; | ||
use crate::IonResult; | ||
use std::io::Write; | ||
|
||
/// Associates a value to serialize with a sequence of annotations. | ||
pub struct Annotated<'a, T: ?Sized, A> { | ||
value: &'a T, | ||
annotations: &'a [A], | ||
} | ||
|
||
/// Provides implementors with an extension method ([`annotate`](Annotate::annotate)) that allows | ||
/// Provides implementors with an extension method ([`annotate`](Annotate::annotated_with)) that allows | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗺️ Renamed |
||
/// them to be serialized with an associated sequence of annotations. | ||
pub trait Annotate { | ||
/// Pairs a reference to the provided value with a slice containing annotations. | ||
|
@@ -19,13 +18,13 @@ pub trait Annotate { | |
///# use ion_rs::IonResult; | ||
///# fn main() -> IonResult<()> { | ||
/// use ion_rs::{Element, IonData}; | ||
/// use ion_rs::lazy::encoder::LazyRawTextWriter_1_0; | ||
/// use ion_rs::lazy::encoder::text::LazyRawTextWriter_1_0; | ||
/// use ion_rs::lazy::encoder::annotate::Annotate; | ||
/// | ||
/// let mut buffer = vec![]; | ||
/// let mut writer = LazyRawTextWriter_1_0::new(&mut buffer); | ||
/// | ||
/// writer.write(42_usize.annotate(&["foo", "bar", "baz"]))?.flush()?; | ||
/// writer.write(42_usize.annotated_with(&["foo", "bar", "baz"]))?.flush()?; | ||
/// | ||
/// let expected = Element::read_one("foo::bar::baz::42")?; | ||
/// let actual = Element::read_one(&buffer)?; | ||
|
@@ -34,7 +33,7 @@ pub trait Annotate { | |
///# Ok(()) | ||
///# } | ||
/// ``` | ||
fn annotate<'a, A: AsRawSymbolTokenRef>( | ||
fn annotated_with<'a, A: AsRawSymbolTokenRef>( | ||
&'a self, | ||
annotations: &'a [A], | ||
) -> Annotated<'a, Self, A>; | ||
|
@@ -43,9 +42,9 @@ pub trait Annotate { | |
// Any Rust value that can be serialized as an Ion value can call `annotate`. | ||
impl<T> Annotate for T | ||
where | ||
T: WriteAsIonValue, | ||
T: ?Sized + WriteAsIonValue, | ||
{ | ||
fn annotate<'a, A: AsRawSymbolTokenRef>( | ||
fn annotated_with<'a, A: AsRawSymbolTokenRef>( | ||
&'a self, | ||
annotations: &'a [A], | ||
) -> Annotated<'a, Self, A> { | ||
|
@@ -58,16 +57,23 @@ where | |
|
||
// The `Annotated` struct implements `WriteAsIon` by serializing its sequence of annotations | ||
// and then invoking the inner value's implementation of `WriteAsIonValue`. | ||
impl<'b, T, A> WriteAsIon for Annotated<'b, T, A> | ||
impl<'annotations, T, A> WriteAsIon for Annotated<'annotations, T, A> | ||
where | ||
T: WriteAsIonValue, | ||
A: AsRawSymbolTokenRef, | ||
{ | ||
fn write_as_ion<'a, W: Write + 'a, E: LazyEncoder<W>, V: AnnotatedValueWriter<'a, W, E>>( | ||
&self, | ||
annotations_writer: V, | ||
) -> IonResult<()> { | ||
let value_writer = annotations_writer.write_annotations(self.annotations.iter())?; | ||
fn write_as_ion<V: AnnotatableValueWriter>(&self, writer: V) -> IonResult<()> { | ||
let value_writer = writer.with_annotations(self.annotations); | ||
self.value.write_as_ion_value(value_writer) | ||
} | ||
} | ||
|
||
impl<'annotations, T, A> WriteAsIon for &Annotated<'annotations, T, A> | ||
where | ||
T: WriteAsIonValue, | ||
A: AsRawSymbolTokenRef, | ||
{ | ||
fn write_as_ion<V: AnnotatableValueWriter>(&self, writer: V) -> IonResult<()> { | ||
(*self).write_as_ion(writer) | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗺️ The
std
feature supplies an implementation ofstd::io::Write
forbumpalo
'sVec
type. (Aliased toBumpVec
in this codebase.)