You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The writer returned by JsonWriter::string_value_writer only supports writing valid UTF-8 data. However, currently it is a io::Write and therefore allows writing arbitrary bytes, which might not be valid UTF-8 data, and which therefore requires validation and buffering of incomplete / split UTF-8 data.
Enhancement description
Instead of using io::Write, use std::fmt::Write which only allows valid UTF-8 data. This would then avoid having to manually perform UTF-8 validation and handle incomplete UTF-8 data.
It would however lose the flush() method, but that was mainly implemented for the current implementation because io::Write includes it by default, not necessarily because it is really needed.
The question is though whether the string value writer should still in addition to std::fmt::Write also implement io::Write for the cases where users want to use a io::Write, for example when transferring data from a text file to the string value writer.
Problem solved by the enhancement
The writer returned by
JsonWriter::string_value_writer
only supports writing valid UTF-8 data. However, currently it is aio::Write
and therefore allows writing arbitrary bytes, which might not be valid UTF-8 data, and which therefore requires validation and buffering of incomplete / split UTF-8 data.Enhancement description
Instead of using
io::Write
, usestd::fmt::Write
which only allows valid UTF-8 data. This would then avoid having to manually perform UTF-8 validation and handle incomplete UTF-8 data.It would however lose the
flush()
method, but that was mainly implemented for the current implementation becauseio::Write
includes it by default, not necessarily because it is really needed.The question is though whether the string value writer should still in addition to
std::fmt::Write
also implementio::Write
for the cases where users want to use aio::Write
, for example when transferring data from a text file to the string value writer.This was originally mentioned in https://users.rust-lang.org/t/error-handling-for-custom-read-read-write-write-implementation/101742/11
The text was updated successfully, but these errors were encountered: