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
Error recovery by rewinding the stream on parse failure is implemented only in the derive and the default impls. Requiring manual implementations to handle this themselves is error-prone, remembering to consistently implement it in BinRead itself is error-prone, and manually tracking and reporting the position of the field/struct/variant which failed to be read successfully is error-prone. Consider something like splitting the API so read_options becomes something like:
…and then read_options_impl (bikeshed name) is where the actual implementation goes, so any error recovery can be fully uniform (and more options could be made available if someone requests them, e.g. if someone prefers to have a stream end in an undefined state or receive no position information on error in exchange for fewer seeks).
This may actually be impossible to fully realise because it would require calls from inside another read_options to become read_options_impl or whatever and only callees that are not read_options would call through a wrapper? At the least some helper functions can exist to make this job easier, because I’ve already written them for myself.
The other part of this is to make it easier to actually generate errors, since right now it is a bit verbose and could probably be easier. A helper that records the position and makes it easy to call an error probably. Similar to syn::parse::Lookahead1 maybe?; any thing which checkpoints positions and has some easy method to call that bails with the error.
The text was updated successfully, but these errors were encountered:
Copied from #9:
Error recovery by rewinding the stream on parse failure is implemented only in the derive and the default impls. Requiring manual implementations to handle this themselves is error-prone, remembering to consistently implement it in BinRead itself is error-prone, and manually tracking and reporting the position of the field/struct/variant which failed to be read successfully is error-prone. Consider something like splitting the API so
read_options
becomes something like:…and then
read_options_impl
(bikeshed name) is where the actual implementation goes, so any error recovery can be fully uniform (and more options could be made available if someone requests them, e.g. if someone prefers to have a stream end in an undefined state or receive no position information on error in exchange for fewer seeks).This may actually be impossible to fully realise because it would require calls from inside another read_options to become read_options_impl or whatever and only callees that are not read_options would call through a wrapper? At the least some helper functions can exist to make this job easier, because I’ve already written them for myself.
The other part of this is to make it easier to actually generate errors, since right now it is a bit verbose and could probably be easier. A helper that records the position and makes it easy to call an error probably. Similar to
syn::parse::Lookahead1
maybe?; any thing which checkpoints positions and has some easy method to call that bails with the error.The text was updated successfully, but these errors were encountered: