10
10
11
11
//! Exposes the NonZero lang item which provides optimization hints.
12
12
13
- use cmp:: Eq ;
14
- use intrinsics;
15
- use kinds:: Copy ;
16
13
use ops:: Deref ;
17
- use option:: Option ;
18
- use option:: Option :: Some ;
19
- use ptr:: { null, null_mut, RawPtr , RawMutPtr } ;
20
14
21
15
/// A wrapper type for raw pointers and integers that will never be
22
16
/// NULL or 0 that might allow certain optimizations.
23
17
#[ lang="non_zero" ]
24
- #[ deriving( Clone , PartialEq , Eq , PartialOrd ) ]
18
+ #[ deriving( Copy , Clone , Eq , PartialEq , Ord , PartialOrd , Show ) ]
25
19
#[ experimental]
26
20
pub struct NonZero < T > ( T ) ;
27
21
@@ -34,65 +28,10 @@ impl<T> NonZero<T> {
34
28
}
35
29
}
36
30
37
- impl < T : Copy > Copy for NonZero < T > { }
38
-
39
31
impl < T > Deref < T > for NonZero < T > {
40
32
#[ inline]
41
33
fn deref < ' a > ( & ' a self ) -> & ' a T {
42
34
let NonZero ( ref inner) = * self ;
43
35
inner
44
36
}
45
37
}
46
-
47
- impl < T > RawPtr < T > for NonZero < * const T > {
48
- #[ inline]
49
- fn null ( ) -> NonZero < * const T > { NonZero ( null ( ) ) }
50
-
51
- #[ inline]
52
- fn is_null ( & self ) -> bool { false }
53
-
54
- #[ inline]
55
- fn to_uint ( & self ) -> uint {
56
- * * self as uint
57
- }
58
-
59
- #[ inline]
60
- unsafe fn offset ( self , count : int ) -> NonZero < * const T > {
61
- NonZero ( intrinsics:: offset ( * self , count) )
62
- }
63
-
64
- #[ inline]
65
- unsafe fn as_ref < ' a > ( & self ) -> Option < & ' a T > {
66
- Some ( & * * * self )
67
- }
68
- }
69
-
70
- impl < T > RawPtr < T > for NonZero < * mut T > {
71
- #[ inline]
72
- fn null ( ) -> NonZero < * mut T > { NonZero ( null_mut ( ) ) }
73
-
74
- #[ inline]
75
- fn is_null ( & self ) -> bool { false }
76
-
77
- #[ inline]
78
- fn to_uint ( & self ) -> uint {
79
- * * self as uint
80
- }
81
-
82
- #[ inline]
83
- unsafe fn offset ( self , count : int ) -> NonZero < * mut T > {
84
- NonZero ( intrinsics:: offset ( * self as * const T , count) as * mut T )
85
- }
86
-
87
- #[ inline]
88
- unsafe fn as_ref < ' a > ( & self ) -> Option < & ' a T > {
89
- Some ( & * * * self )
90
- }
91
- }
92
-
93
- impl < T > RawMutPtr < T > for NonZero < * mut T > {
94
- #[ inline]
95
- unsafe fn as_mut < ' a > ( & self ) -> Option < & ' a mut T > {
96
- Some ( & mut * * * self )
97
- }
98
- }
0 commit comments