Marcono1234 / struson

Streaming JSON reader and writer written in Rust
https://crates.io/crates/struson
Apache License 2.0
59 stars 6 forks source link

[simple-api] Add string value reader & writer methods #54

Closed Marcono1234 closed 6 months ago

Marcono1234 commented 6 months ago

Problem solved by the enhancement

Currently the Simple API only supports reading JSON string values as str / String. For larger string values it might useful if they could be read using a Read and written using a Write, similar to what the Advanced API offers with JsonReader::next_string_reader and JsonWriter::string_value_writer.

Enhancement description

Add methods to the Simple API which are similar and delegate to the Advanced API. They should have an FnOnce -> T as parameter which takes a Read / Write (respectively custom struct) as argument. For example:

(or similar names)

Should probably not expose the traits from the Advanced API (currently only JsonWriter::string_value_writer has a custom trait) since they provide functionality which is redundant or might interfere with the Simple API behavior, e.g. StringValueWriter::finish_value, and because their documentation might be misleading for the Simple API.

The documentation for these methods should then probably have the same notes about reader and writer errors as the Advanced API, namely that reading / writing should be stopped even if Read or Write might permit retrying normally.

Alternatives / workarounds

Use the Advanced API