Add de::from_str_with_whitespace
and de::from_reader_with_whitespace
#855
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.
My goal was to mimic the pattern from the procedural
Reader
in the declarativeDeserializer
. This would involve creating a configuration struct that is owned byDeserializer
and mutating it before callingfrom_str
orfrom_reader
, similar to below.Since
from_str
andfrom_reader
form the entire public interface for thede
module, we need to create two new functions to maintain backward compatibility:from_str_with_whitespace
from_reader_with_whitespace
The configuration needs to be interpreted in two places, since trimming the start of the text happens in a separate procedure from trimming the end of the text. When we construct a
Deserializer
, it creates anXmlReader
, which containers either aSliceReader
or anIoReader
. Both of those readers take aStartTrimmer
, which has two jobs for each xmlEvent
:Event
s intoPayloadEvent
s, andFor each
Event
, theSliceReader
orIoReader
trims and processes it, handing aPayloadEvent
toXmlReader
. TheXmlReader
takes thePayloadEvent
, trims the end before decoding, and hands backDeEvent
s. At this point, all trimming is complete. TheDeserializer
then decodes the trimmedDeEvent
s.XmlReader
shall own theDeConfig
object, since that is the lowest-level common object that touches both the start-of-string and end-of-string trimming. Recall thatXmlReader
, which trims the end, ownsIoReader
andSliceReader
, one of which trim the start.