#infallible #refactoring #conversion #maintainability #error-value #convert #never-type

unwrap-infallible

Unwrapping Result values with compile-time guarantee of infallibility

6 releases

0.1.5 Dec 16, 2019
0.1.4 Dec 11, 2019
0.1.3 Nov 9, 2019
0.1.2 Oct 31, 2019

#972 in Rust patterns

Download history 2671/week @ 2023-11-29 2913/week @ 2023-12-06 2758/week @ 2023-12-13 1594/week @ 2023-12-20 1435/week @ 2023-12-27 3300/week @ 2024-01-03 4087/week @ 2024-01-10 5690/week @ 2024-01-17 3979/week @ 2024-01-24 5389/week @ 2024-01-31 4733/week @ 2024-02-07 4653/week @ 2024-02-14 5661/week @ 2024-02-21 5332/week @ 2024-02-28 5743/week @ 2024-03-06 4502/week @ 2024-03-13

21,990 downloads per month
Used in 16 crates (9 directly)

MIT/Apache

7KB
53 lines

Unwrapping Results With Compile-Time Guarantee of Infallibility

The Rust standard type Result sometimes occurs parameterized with an error type that has no possible values, such as std::convert::Infallible. Consequently, calling the unwrap method on a Result value of such a type will never panic. Therein lies a maintainability hazard: if the error parameter type is later changed to one that can represent actually occurring errors, those uses of unwrap that could previously be relied upon to be infallible, quietly become liable to panic.

To help prevent this from happening without a compile-time safeguard, this crate provides an alternative method unwrap_infallible that shall only be available for Result values with a known-impossible Err variant.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps

Features