Splits MakeValueWriter
into two traits
#867
Merged
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.
This patch contains no logic changes, only a refactoring of the
MakeValueWriter
trait.Instances of
ValueWriter
are single-use by design, as this allows the crate tostatically guarantee that an application cannot (for example) try to encode multiple
values following an annotations sequence or inside a struct field.
Prior to this PR, the
MakeValueWriter
trait was public for testing purposes.This allowed applications to refer to a container's associated
ValueWriter
family of types,which was needed for custom writer methods leveraging generics.
For example, a list writer at the top level of a stream might be written as:
(This is admittedly very ugly, but alas there is no way to offer a nice shortcut for this case.)
While exposing
MakeValueWriter
allowed applications to concretely reference associated type paths,it also exposed the
make_value_writer
method.make_value_writer
needs to be kept private toprevent users from circumventing
ValueWriter
's statically enforced single-use restriction,creating and then using multiple value writers in situations where that would produce illegal data.
This PR splits
MakeValueWriter
into two traits:ContextWriter
, which houses the associated typesand
MakeValueWriter
, which houses themake_value_writer
method and, by extendingContextWriter
, has access to the necessary associated typesContextWriter
is public/re-exported, allowing applications to refer to associated types as needed.MakeValueWriter
is nowpub(crate)
and is no longer re-exported at the top level.The example variable declaration above would now be written:
This PR supersedes #864 and fixes #863.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.