Skip to content

Commit f775292

Browse files
committed
---
yaml --- r: 147452 b: refs/heads/try2 c: 1ca7726 h: refs/heads/master v: v3
1 parent e1dbe9c commit f775292

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
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 76270816d527bfceef64bf6cbdc64f985ca73eba
8+
refs/heads/try2: 1ca77268d97b62e2fcaa1642aaf9313e164963b3
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/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)