(index<- ) ./libstd/managed.rs
git branch: * master c7553ea auto merge of #13609 : richo/rust/str-type-vim, r=alexcrichton
modified: Wed Mar 26 11:50:03 2014
1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 //! Operations on managed box types
12
13 #[cfg(not(test))] use cmp::*;
14
15 /// Determine if two shared boxes point to the same object
16 #[inline]
17 pub fn ptr_eq<T>(a: @T, b: @T) -> bool {
18 &*a as *T == &*b as *T
19 }
20
21 #[cfg(not(test))]
22 impl<T:Eq> Eq for @T {
23 #[inline]
24 fn eq(&self, other: &@T) -> bool { *(*self) == *(*other) }
25 #[inline]
26 fn ne(&self, other: &@T) -> bool { *(*self) != *(*other) }
27 }
28
29 #[cfg(not(test))]
30 impl<T:Ord> Ord for @T {
31 #[inline]
32 fn lt(&self, other: &@T) -> bool { *(*self) < *(*other) }
33 #[inline]
34 fn le(&self, other: &@T) -> bool { *(*self) <= *(*other) }
35 #[inline]
36 fn ge(&self, other: &@T) -> bool { *(*self) >= *(*other) }
37 #[inline]
38 fn gt(&self, other: &@T) -> bool { *(*self) > *(*other) }
39 }
40
41 #[cfg(not(test))]
42 impl<T: TotalOrd> TotalOrd for @T {
43 #[inline]
44 fn cmp(&self, other: &@T) -> Ordering { (**self).cmp(*other) }
45 }
46
47 #[cfg(not(test))]
48 impl<T: TotalEq> TotalEq for @T {}
49
50 #[test]
51 fn test() {
52 let x = @3;
53 let y = @3;
54 assert!((ptr_eq::<int>(x, x)));
55 assert!((ptr_eq::<int>(y, y)));
56 assert!((!ptr_eq::<int>(x, y)));
57 assert!((!ptr_eq::<int>(y, x)));
58 }