@@ -935,8 +935,8 @@ impl<T, E: fmt::Debug> Result<T, E> {
935
935
///
936
936
/// # Panics
937
937
///
938
- /// Panics if the value is an [`Err`], with a panic message provided by the
939
- /// [`Err`]'s value .
938
+ /// Panics if the value is an [`Err`], with a panic message including the
939
+ /// passed message, and the content of the [`Err`].
940
940
///
941
941
/// [`Ok`]: enum.Result.html#variant.Ok
942
942
/// [`Err`]: enum.Result.html#variant.Err
@@ -945,31 +945,26 @@ impl<T, E: fmt::Debug> Result<T, E> {
945
945
///
946
946
/// Basic usage:
947
947
///
948
- /// ```
949
- /// let x: Result<u32, &str> = Ok(2);
950
- /// assert_eq!(x.unwrap(), 2);
951
- /// ```
952
- ///
953
948
/// ```{.should_panic}
954
949
/// let x: Result<u32, &str> = Err("emergency failure");
955
- /// x.unwrap( ); // panics with `emergency failure`
950
+ /// x.expect("Testing expect" ); // panics with `Testing expect: emergency failure`
956
951
/// ```
957
952
#[ inline]
958
953
#[ track_caller]
959
- #[ stable( feature = "rust1 " , since = "1.0 .0" ) ]
960
- pub fn unwrap ( self ) -> T {
954
+ #[ stable( feature = "result_expect " , since = "1.4 .0" ) ]
955
+ pub fn expect ( self , msg : & str ) -> T {
961
956
match self {
962
957
Ok ( t) => t,
963
- Err ( e) => unwrap_failed ( "called `Result::unwrap()` on an `Err` value" , & e) ,
958
+ Err ( e) => unwrap_failed ( msg , & e) ,
964
959
}
965
960
}
966
961
967
962
/// Unwraps a result, yielding the content of an [`Ok`].
968
963
///
969
964
/// # Panics
970
965
///
971
- /// Panics if the value is an [`Err`], with a panic message including the
972
- /// passed message, and the content of the [`Err`].
966
+ /// Panics if the value is an [`Err`], with a panic message provided by the
967
+ /// [`Err`]'s value .
973
968
///
974
969
/// [`Ok`]: enum.Result.html#variant.Ok
975
970
/// [`Err`]: enum.Result.html#variant.Err
@@ -978,17 +973,22 @@ impl<T, E: fmt::Debug> Result<T, E> {
978
973
///
979
974
/// Basic usage:
980
975
///
976
+ /// ```
977
+ /// let x: Result<u32, &str> = Ok(2);
978
+ /// assert_eq!(x.unwrap(), 2);
979
+ /// ```
980
+ ///
981
981
/// ```{.should_panic}
982
982
/// let x: Result<u32, &str> = Err("emergency failure");
983
- /// x.expect("Testing expect" ); // panics with `Testing expect: emergency failure`
983
+ /// x.unwrap( ); // panics with `emergency failure`
984
984
/// ```
985
985
#[ inline]
986
986
#[ track_caller]
987
- #[ stable( feature = "result_expect " , since = "1.4 .0" ) ]
988
- pub fn expect ( self , msg : & str ) -> T {
987
+ #[ stable( feature = "rust1 " , since = "1.0 .0" ) ]
988
+ pub fn unwrap ( self ) -> T {
989
989
match self {
990
990
Ok ( t) => t,
991
- Err ( e) => unwrap_failed ( msg , & e) ,
991
+ Err ( e) => unwrap_failed ( "called `Result::unwrap()` on an `Err` value" , & e) ,
992
992
}
993
993
}
994
994
}
0 commit comments