Relax Logos::Error bounds - #570
Open
DavidCrossman wants to merge 2 commits into
Open
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #570 +/- ##
=======================================
Coverage 73.66% 73.66%
=======================================
Files 29 29
Lines 1929 1929
=======================================
Hits 1421 1421
Misses 508 508 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation
Logos::Errorhas several trait bounds which are not necessarily required. These extra bounds impose restrictions on the custom error type the user provides. In particular, theDefaultbound may require adding a#[default] Othervariant to an error enum even if an error callback is specified.Relaxing the
DefaultboundThere are three cases to consider:
For (1), the fallback error type is
(), which implementsDefault, so the bound is irrelevant.For (2), the user's error callback is called rather than
Default::default, so the bound isn't needed.For (3), the
_make_errorfunction will fallback toDefault::default. If the custom error type doesn't implementDefault, this will cause a type error. The user gets an error message suggesting to implementDefaulton the custom error type.This makes the
Defaultbound required only if the user does not provide an error callback (case (3)), rather than unconditionally. TheLogosderive already uses this technique to requireInto<CustomErrorType>for each callback's error type. Relaxing theDefaultbound in this way would be backwards compatible.Examples and Book
I've updated the book to reflect these changes. I have also simplified the examples which use error callbacks.
Relation to #459
This PR encompasses #459, so it could be merged before this PR (or closed).