This repository was archived by the owner on Jul 1, 2025. It is now read-only.
Fallible visitor methods #52
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Makes
Visitormethods fallible (except forend_game). You can see why this is useful in action in the examples (particularly the new one,extract_fen). It makes error handling for users a lot cleaner.Users who don't need error handling can simply use
Infallibleas the error type.What happens after an error
The reader continues to parse the game even if the visitor errors, it just doesn't call any visitor methods afterwards. Early returns would be nice, but they corrupt the reader/split games. This means that there's no extra functionality in this PR, just a nicer API.
Example
Here's an example of an old way of handling fallible visitors:
Alternative might be to store
Option<NoFenError>and mergeNoFenInnerintoNoFen.Here's equivalent code with this PR:
As you can see, it's a lot nicer.