Implementing diesel::result::DatabaseErrorInformation for Infallible
#4951
Closed
LucaCappelletti94
started this conversation in
Ideas
Replies: 1 comment
-
|
Closing as completed with PR #4952 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Backend
PostgreSQL, MySQL, SQLite, Others
What do you want to add to diesel?
At the moment I have an error type of the form:
I implement
DatabaseErrorInformationforError<E>wheneverE: DatabaseErrorInformation, by delegating to the inner error for theValidationvariant and providing static information for the others.In some use cases I want to express that validation is always correct, i.e.
Error<Infallible>. However, this currently does not type-check because std::convert::Infallible does not implementDatabaseErrorInformation.From a semantic point of view,
Infallibleis an uninhabited type and can never be instantiated, so any implementation ofDatabaseErrorInformationfor it would be unreachable at runtime. Still, due to the orphan rules, it is impossible to provide such an implementation downstream.This would allow generic error types to use
Infallibleas a marker for “this branch cannot occur”, without requiring ad-hoc wrapper types or loss of type information.Implementation notes
Would it be acceptable for Diesel to provide a built-in implementation like:
This is statically unreachable code: there is no panic path and no runtime behavior, just a type-level proof that the methods cannot be called.
Additional details
No response
Checklist
Beta Was this translation helpful? Give feedback.
All reactions