Skip to content

Commit a5718ba

Browse files
author
Brian J. Burg
committed
Change option::expect to not require a Copy bound, and move instead.
1 parent 1702024 commit a5718ba

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/libcore/option.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,17 @@ pub pure fn get_ref<T>(opt: &r/Option<T>) -> &r/T {
8585
}
8686
}
8787

88-
pub pure fn expect<T: Copy>(opt: Option<T>, reason: ~str) -> T {
88+
pub pure fn expect<T>(opt: Option<T>, reason: ~str) -> T {
8989
/*!
90-
* Gets the value out of an option, printing a specified message on
91-
* failure
90+
* Gets the value out of an option without copying, printing a
91+
* specified message on failure.
9292
*
9393
* # Failure
9494
*
9595
* Fails if the value equals `none`
9696
*/
97-
match opt { Some(copy x) => x, None => fail reason }
97+
if opt.is_some() { move option::unwrap(move opt) }
98+
else { fail reason }
9899
}
99100

100101
pub pure fn map<T, U>(opt: &Option<T>, f: fn(x: &T) -> U) -> Option<U> {

0 commit comments

Comments
 (0)