From a5718ba377fbc915618062d7562229a4eb754c9f Mon Sep 17 00:00:00 2001 From: "Brian J. Burg" Date: Thu, 8 Nov 2012 16:25:22 -0800 Subject: [PATCH] Change option::expect to not require a Copy bound, and move instead. --- src/libcore/option.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 3b1d2079800..0bb3262e569 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -85,16 +85,17 @@ pub enum Option { } } -pub pure fn expect(opt: Option, reason: ~str) -> T { +pub pure fn expect(opt: Option, reason: ~str) -> T { /*! - * Gets the value out of an option, printing a specified message on - * failure + * Gets the value out of an option without copying, printing a + * specified message on failure. * * # Failure * * Fails if the value equals `none` */ - match opt { Some(copy x) => x, None => fail reason } + if opt.is_some() { move option::unwrap(move opt) } + else { fail reason } } pub pure fn map(opt: &Option, f: fn(x: &T) -> U) -> Option {