Skip to content

Commit 751f09a

Browse files
committed
---
yaml --- r: 96912 b: refs/heads/dist-snap c: 1ca7726 h: refs/heads/master v: v3
1 parent fef29b6 commit 751f09a

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
@@ -6,7 +6,7 @@ refs/heads/try: c274a6888410ce3e357e014568b43310ed787d36
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: 76270816d527bfceef64bf6cbdc64f985ca73eba
9+
refs/heads/dist-snap: 1ca77268d97b62e2fcaa1642aaf9313e164963b3
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/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)