Skip to content

Commit d1230c8

Browse files
committed
---
yaml --- r: 88836 b: refs/heads/snap-stage3 c: 1ca7726 h: refs/heads/master v: v3
1 parent 52dd33e commit d1230c8

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: deeca5d586bfaa4aa60246f671a8d611d38f6248
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 76270816d527bfceef64bf6cbdc64f985ca73eba
4+
refs/heads/snap-stage3: 1ca77268d97b62e2fcaa1642aaf9313e164963b3
55
refs/heads/try: b160761e35efcd1207112b3b782c06633cf441a8
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libstd/any.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
2121
use cast::transmute;
2222
use option::{Option, Some, None};
23+
use result::{Result, Ok, Err};
2324
use to_str::ToStr;
25+
use unstable::intrinsics::TypeId;
2426
use unstable::intrinsics;
2527
use util::Void;
26-
use unstable::intrinsics::TypeId;
2728

2829
///////////////////////////////////////////////////////////////////////////////
2930
// Any trait
@@ -119,12 +120,12 @@ impl<'a> AnyMutRefExt<'a> for &'a mut Any {
119120
pub trait AnyOwnExt {
120121
/// Returns the boxed value if it is of type `T`, or
121122
/// `None` if it isn't.
122-
fn move<T: 'static>(self) -> Option<~T>;
123+
fn move<T: 'static>(self) -> Result<~T, Self>;
123124
}
124125

125126
impl AnyOwnExt for ~Any {
126127
#[inline]
127-
fn move<T: 'static>(self) -> Option<~T> {
128+
fn move<T: 'static>(self) -> Result<~T, ~Any> {
128129
if self.is::<T>() {
129130
unsafe {
130131
// Extract the pointer to the boxed value, temporary alias with self
@@ -133,10 +134,10 @@ impl AnyOwnExt for ~Any {
133134
// Prevent destructor on self being run
134135
intrinsics::forget(self);
135136

136-
Some(ptr)
137+
Ok(ptr)
137138
}
138139
} else {
139-
None
140+
Err(self)
140141
}
141142
}
142143
}
@@ -384,13 +385,13 @@ mod tests {
384385
let a = ~8u as ~Any;
385386
let b = ~Test as ~Any;
386387

387-
assert_eq!(a.move(), Some(~8u));
388-
assert_eq!(b.move(), Some(~Test));
388+
assert_eq!(a.move(), Ok(~8u));
389+
assert_eq!(b.move(), Ok(~Test));
389390

390391
let a = ~8u as ~Any;
391392
let b = ~Test as ~Any;
392393

393-
assert_eq!(a.move(), None::<~Test>);
394-
assert_eq!(b.move(), None::<~uint>);
394+
assert!(a.move::<~Test>().is_err());
395+
assert!(b.move::<~uint>().is_err());
395396
}
396397
}

0 commit comments

Comments
 (0)