Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tb: add support for Variant Types #22

Merged
merged 2 commits into from
Aug 31, 2024
Merged

tb: add support for Variant Types #22

merged 2 commits into from
Aug 31, 2024

Conversation

r-bk
Copy link
Owner

@r-bk r-bk commented Aug 23, 2024

Variant Types are ZSTs created for error kinds. They are useful when a function has only a single error condition. In such cases returning a full-fledged Error may be excessive because that forces a caller to handle a non-exhaustive list of errors. With Variant Types the return code is exhaustive, making error handling simpler.

Note that Variant Types are marked #[non_exhaustive] to forbid their creation outside their origin crate. This doesn't affect a function that returns such type. A caller of such function still needs to handle only a single error.

Variant Types may be enhanced in future to contain custom fields. This will allow returning rich information about errors.

Variant Types are implicitly convertible to Kind and Error so propagating them through layers of abstraction is seamless as tighterror aims to be.

Copy link
Owner Author

@r-bk r-bk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test review before force-push of the PR branch.

Copy link
Owner Author

@r-bk r-bk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test finish review before force-push.

fn test_module_variant_type() {
log_init();

for val in [true, false] {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test review comment before force-push.

Variant Types are ZSTs created for error kinds. They are useful when a
function has only a single error condition. In such cases returning a
full-fledged Error may be excessive because that forces a caller to
handle a non-exhaustive list of errors. With Variant Types the return
code is exhaustive, making error handling simpler.

Note that Variant Types are marked `#[non_exhaustive]` to forbid their
creation outside their origin crate. This doesn't affect a function that
returns such type. A caller of such function still needs to handle only
a single error.

Variant Types may be enhanced in future to contain custom fields. This
will allow returning rich information about errors.

Variant Types are implicitly convertible to Kind and Error so
propagating them through layers of abstraction is seamless as tighterror
aims to be.
@r-bk r-bk merged commit 65a33f6 into main Aug 31, 2024
12 checks passed
@r-bk r-bk deleted the variant_types branch August 31, 2024 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant