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.
Unfortunately, the
repr
feature does not work and fundamentally cannot work efficiently because the write-side always receives references to values, but (1) there are noFrom<&T>
conversions for any std type that anyone would use as a repr, and (2) this would cause a complete copy of the converted object to be retained in memory just to write the object. So this PR removesrepr
entirely from the library and replaces it with something that definitely doesn’t have any of its own serious flaws or unnecessary complexity 👁️👄👁️.The replacement feature,
with
, uses separate conversion types.To use a conversion type, there are a few options: the attribute (e.g.
#[brw(with(NullString))] field: String
), theWith
wrapper (e.g.field: With<NullString, String>
), or by calling the methods of the newReadWith
andWriteWith
traits or the new methods on the existingBinReaderExt
andBinWriterExt
traits.To implement a conversion type, implement
ReadFrom<ConverterT> for T
andWriteInto<ConverterT> for T
. A converter can be used with many types; for example, in this patch, theNullString
converter is implemented to read intoVec<u8>
andString
types, and to write from[u8]
,str
, orString
types. (n.b. Should that actually use a generic for anything that is likeAsRef<[u8]>
? Maybe, please bring it up in a code review!)Since this creates a new idiom for how to serialise objects that don’t have obvious default serialisations (i.e.
String
), theNullString
andNullWideString
types are no longer containers, but rather just converters. Authors would switch to use an appropriate concrete type (Vec<u8>
orString
) and thewith
directive, or else theWith
wrapper class.This patch doesn’t yet include any intermediate trait to enable third party to third party conversions as mentioned in #98. The number of different ways to do custom parsing is starting to feel a little burdensome; this seemed like a place to start.