From 896cfcc67fb8d3e53a5dcf138f79909891bf940e Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 2 Jun 2014 15:49:42 -0700 Subject: std: Remove generics from Option::expect This commit removes the type parameter from Option::expect in favor of just taking a hard-coded `&str` argument. This allows this function to move into libcore. Previous code using strings with `expect` will continue to work, but code using this implicitly to transmit task failure will need to unwrap manually with a `match` statement. [breaking-change] Closes #14008 --- src/libcore/option.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/libcore') diff --git a/src/libcore/option.rs b/src/libcore/option.rs index b91a8cebded..45ccf657dbd 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -233,6 +233,20 @@ impl Option { // Getting to contained values ///////////////////////////////////////////////////////////////////////// + /// Unwraps an option, yielding the content of a `Some` + /// + /// # Failure + /// + /// Fails if the value is a `None` with a custom failure message provided by + /// `msg`. + #[inline] + pub fn expect(self, msg: &str) -> T { + match self { + Some(val) => val, + None => fail!(msg), + } + } + /// Moves a value out of an option type and returns it, consuming the `Option`. /// /// # Failure -- cgit 1.4.1-3-g733a5