1010
1111//! Exposes the NonZero lang item which provides optimization hints.
1212
13- use cmp:: Eq ;
14- use intrinsics;
15- use kinds:: Copy ;
1613use ops:: Deref ;
17- use option:: Option ;
18- use option:: Option :: Some ;
19- use ptr:: { null, null_mut, RawPtr , RawMutPtr } ;
2014
2115/// A wrapper type for raw pointers and integers that will never be
2216/// NULL or 0 that might allow certain optimizations.
2317#[ lang="non_zero" ]
24- #[ deriving( Clone , PartialEq , Eq , PartialOrd ) ]
18+ #[ deriving( Copy , Clone , Eq , PartialEq , Ord , PartialOrd , Show ) ]
2519#[ experimental]
2620pub struct NonZero < T > ( T ) ;
2721
@@ -34,65 +28,10 @@ impl<T> NonZero<T> {
3428 }
3529}
3630
37- impl < T : Copy > Copy for NonZero < T > { }
38-
3931impl < T > Deref < T > for NonZero < T > {
4032 #[ inline]
4133 fn deref < ' a > ( & ' a self ) -> & ' a T {
4234 let NonZero ( ref inner) = * self ;
4335 inner
4436 }
4537}
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