Add FromSqlError::other convenience conversion#1703
Merged
gwenn merged 1 commit intorusqlite:masterfrom May 29, 2025
Merged
Conversation
When implementing `FromSql` it is common (as demonstrated by this commit diff) to call into a lower-level parsing function (such as `str::from_utf8`) and then convert the returned error to `FromSqlError::Other`. However this required manual boxing and unsizing which made the code a bit annoying. Thus this commit introduces an `other` generic method intentionally named after the `Other` variant. This method performs the boxing and unsizing so that callers can use it instead of writing a closure with `Box::new` (if `map_err` is used). This commit also replaces all such occurrences in the `rusqlite`'s code which not only simplifies the code but also demonstrates the usefulness of the method. Incidentally, the change also simplifies manual `match`es to use `map_err` instead as well as replaces `FromStr` with the more idiomatic `parse` method in the those places.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1703 +/- ##
==========================================
+ Coverage 87.83% 87.84% +0.01%
==========================================
Files 58 58
Lines 11389 11379 -10
==========================================
- Hits 10003 9996 -7
+ Misses 1386 1383 -3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Collaborator
|
Thanks. |
Collaborator
|
rusqlite version 0.37.0 released |
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.
When implementing
FromSqlit is common (as demonstrated by this commit diff) to call into a lower-level parsing function (such asstr::from_utf8) and then convert the returned error toFromSqlError::Other. However this required manual boxing and unsizing which made the code a bit annoying. Thus this commit introduces anothergeneric method intentionally named after theOthervariant. This method performs the boxing and unsizing so that callers can use it instead of writing a closure withBox::new(ifmap_erris used).This commit also replaces all such occurrences in the
rusqlite's code which not only simplifies the code but also demonstrates the usefulness of the method. Incidentally, the change also simplifies manualmatches to usemap_errinstead as well as replacesFromStrwith the more idiomaticparsemethod in the those places.