about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-06-04 20:41:44 -0700
committerbors <bors@rust-lang.org>2014-06-04 20:41:44 -0700
commit422d54bed212b4f0356fb56bbc31c8deef7a6b77 (patch)
treeb343a08725e1e61bb02b3a0fa1427204e7a47587 /src/libcore
parent193574ae1e3881f95afb8b3e385a9e410ac6798a (diff)
parent896cfcc67fb8d3e53a5dcf138f79909891bf940e (diff)
downloadrust-422d54bed212b4f0356fb56bbc31c8deef7a6b77.tar.gz
rust-422d54bed212b4f0356fb56bbc31c8deef7a6b77.zip
auto merge of #14610 : alexcrichton/rust/issue-14008, r=brson
This commit removes the <M: Any + Send> 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
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/option.rs14
1 files changed, 14 insertions, 0 deletions
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<T> Option<T> {
     // 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