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

Add `JsonReader` method for undoing `seek_to` #53

Closed Marcono1234 closed 6 months ago

Marcono1234 commented 6 months ago

Problem solved by the enhancement

After using JsonReader::seek_to and consuming a value it is currently not easily possible to get back to the original nesting level again to continue reading there (except for the top-level with JsonReader::skip_to_top_level).

Enhancement description

Add a method for 'undoing' a seek_to by consuming all remaining array items and object members and closing arrays and objects in reverse order.

The implementation for this was already added for #48 & #49 but is currently internal, see src/reader/simple.rs function undo_seek. It would make sense to move it to JsonReader, but add additional validation there that it properly detects an incorrect state, even if the path is empty (if possible?).

Maybe need a better name for this than 'undo' because it might give the incorrect impression that afterwards the reader is at the exact same position it was before and can read the same value again.

Alternatives / workarounds

Use the Simple API instead of JsonReader? (probably not always possible)