Replies: 1 comment
-
@djkoloski also mentioned this: https://docs.rs/rancor/0.1.0-pre8/rancor/index.html ( |
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
-
See also: #1659
Currently, our fallible APIs return
Option
s, where all error conditions are reported asNone
. This is insufficient for a few reasons:Option
s, there is no distinction in the type system between APIs that have different failure conditions. As a result, reasoning about which error conditions are possible (vs which are statically prevented at compile time) is a matter of reading the documentation on an API rather; the distinction is not visible in the type system.Option
s either because they don't care to distinguish error cases or because they're worried about the performance or binary size implications of richer error reporting.TryFromBytes
(SupportTryFromBytes
- conditional conversion analogous toFromBytes
#5), some users may want to know which byte offsets or which fields caused a fallible conversion to failGeneric error types
Have our APIs take a generic error type which can be constructed from the appropriate "underlying" error conditions. For
FromBytes
conversions, the "underlying" error conditions that some users would want access to would be size and alignment errors. ForTryFromBytes
, there would be much richer conditions, including the offending byte range, the path to the field that was being validated, etc. See rkyv for some prior art here.Here's an example for
Ref
:Users who want to ensure that certain error conditions are impossible can write only the error conditions they want to handle:
Builder pattern
Create a builder that encodes in the type system which checks have already happened. For each check, provide two methods or functions: one which checks at runtime and returns
Option
orResult
, and one which includes the appropriate type bound (e.g.,T: Unaligned
and is infallible.Beta Was this translation helpful? Give feedback.
All reactions