A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://rust-lang.github.io/rfcs/1119-result-expect.html below:

result-expect - The Rust RFC Book

Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Summary

Add an expect method to the Result type, bounded to E: Debug

Motivation

While Result::unwrap exists, it does not allow annotating the panic message with the operation attempted (e.g. what file was being opened). This is at odds to ‘Option’ which includes both unwrap and expect (with the latter taking an arbitrary failure message).

Detailed design

Add a new method to the same impl block as Result::unwrap that takes a &str message and returns T if the Result was Ok. If the Result was Err, it panics with both the provided message and the error value.

The format of the error message is left undefined in the documentation, but will most likely be the following

panic!("{}: {:?}", msg, e)
Drawbacks Alternatives Unresolved questions

Are there any issues with the proposed format of the panic string?


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4