-
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
Adds trait implementations #730
Conversation
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.
🗺️ PR tour
@@ -1494,7 +1494,7 @@ mod value_tests { | |||
let list: Element = ion_list![1, 2, 3].into(); | |||
thread::scope(|_| { | |||
// Move `list` into this scope, demonstrating `Send` | |||
let elements = vec![list]; | |||
let elements = [list]; |
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.
🗺️ Clippy noticed that this vec!
(and the associated heap allocation) is not necessary.
@@ -38,46 +38,6 @@ pub trait AnnotatableValueWriter: Sized { | |||
|
|||
/// Performs no operations and returns a [`ValueWriter`]. | |||
fn without_annotations(self) -> Self::ValueWriter; | |||
|
|||
// Users can call `ValueWriter` methods on the `AnnotatedValueWriter` directly. Doing so | |||
// will implicitly call `without_annotations`. |
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.
🗺️ These default delegated methods mimicked those on ValueWriter
, allowing users to call them on an AnnotatableValueWriter
without first calling with_annotations
or without_annotations
. However, an AnnotatableValueWriter
could not be passed to methods that required an implementation of ValueWriter
.
delegate_value_writer_to!(closure |self_: Self| { | ||
self_.without_annotations() | ||
}); | ||
} |
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 new blanket implementation of ValueWriter
for all AnnotatableValueWriter
s.
@@ -78,87 +78,3 @@ impl MakeValueWriter for Never { | |||
} | |||
|
|||
impl MacroArgsWriter for Never {} | |||
|
|||
impl ValueWriter for Never { |
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.
🗺️ Never
implements many traits so it can be used as a marker to statically indicate unreachable/unused code paths. Previously, Never
implemented both ValueWriter
and AnnotatableValueWriter
; the new blanket impl allows us to eliminate the explicit implementation of ValueWriter
.
Prior to this PR, the
AnnotatableValueWriter
trait provided many of the same methods asValueWriter
for ergonomics. Calls to these methods were delegated to the type returned fromwithout_annotations()
.This patch reifies the relationship between
AnnotatableValueWriter
andValueWriter
by moving the delegated methods into a blanket implementation ofValueWriter
for allAnnotatableValueWriter
implementations. Existing uses of these methods continue to work as expected, but instances of anAnnotatableValueWriter
implementation can now also be passed into methods that expect animpl ValueWriter
.The PR also adds
WriteAsIon
implementations for a variety of Rust int types.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.