Skip to content
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

Use std::fmt::Write for string value writer #22

Open
Marcono1234 opened this issue Oct 28, 2023 · 0 comments
Open

Use std::fmt::Write for string value writer #22

Marcono1234 opened this issue Oct 28, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@Marcono1234
Copy link
Owner

Problem solved by the enhancement

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.

This was originally mentioned in https://users.rust-lang.org/t/error-handling-for-custom-read-read-write-write-implementation/101742/11

@Marcono1234 Marcono1234 added the enhancement New feature or request label Oct 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant