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

feat: Implement WrapError for Option #409

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jalil-salame
Copy link

Implement WrapError for Option<T>. This is inline with anyhow that also implements Context for Option<T>.

The implementation requires us to introduce a DisplayError internal only type, that creates an error from a type that only implements Display (Report::from_adhoc requires the type to also implement Debug, but WrapError only requires it to implement Display).

For this I copied MessageError and adapted it to implement Debug using the underlying type's Display impl. This is a bit of a hack, but anyhow does something similar.

Closes #408

Implement `WrapError` for `Option<T>`. This is inline with `anyhow` that
also implements `Context` for `Option<T>`.

The implementation requires us to introduce a `DisplayError` internal
only type, that creates an error from a type that only implements
`Display` (`Report::from_adhoc` requires the type to also implement
`Debug`, but `WrapError` only requires it to implement `Display`).

For this I copied `MessageError` and adapted it to implement `Debug`
using the underlying type's `Display` impl. This is a bit of a hack, but
anyhow does [something similar][1].

Closes zkat#408

[1]: https://docs.rs/anyhow/latest/src/anyhow/wrapper.rs.html#34
@jalil-salame
Copy link
Author

jalil-salame commented Nov 16, 2024

If you want I can also create a pub(crate) fn from_display in Report that does the same as from_adhoc but without the Debug bound (using DisplayError instead of MessageError).

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.

Implement WrapError for Option
1 participant