eyre-rs / eyre

A trait object based error handling type for easy idiomatic error handling and reporting in Rust applications
Apache License 2.0
1.35k stars 63 forks source link

Extend `Option` with `ok_or_eyre` #129

Closed LeoniePhiline closed 9 months ago

LeoniePhiline commented 9 months ago

Previously, a closure and macro invocation was required to generate a static string error object from an Option::None.

This change adds an extension trait, providing the ok_or_eyre method on the Option type.

Option::ok_or_eyre accepts static error messages and creates Report objects lazily in the None case.

Implements #125

ten3roberts commented 9 months ago

I will merge this now as it looks splendid. If you find a better way to make it discoverable; feel free to open up another PR 😊