@@ -176,7 +176,7 @@ pub trait Ptr<T> {
176
176
pure fn offset( count : uint ) -> self ;
177
177
}
178
178
179
- /// Extension methods for pointers
179
+ /// Extension methods for immutable pointers
180
180
impl < T > * T : Ptr < T > {
181
181
/// Returns true if the pointer is equal to the null pointer.
182
182
#[ inline( always) ]
@@ -191,6 +191,21 @@ impl<T> *T: Ptr<T> {
191
191
pure fn offset ( count : uint ) -> * T { offset ( self , count) }
192
192
}
193
193
194
+ /// Extension methods for mutable pointers
195
+ impl < T > * mut T : Ptr < T > {
196
+ /// Returns true if the pointer is equal to the null pointer.
197
+ #[ inline( always) ]
198
+ pure fn is_null ( ) -> bool { is_null ( self ) }
199
+
200
+ /// Returns true if the pointer is not equal to the null pointer.
201
+ #[ inline( always) ]
202
+ pure fn is_not_null ( ) -> bool { is_not_null ( self ) }
203
+
204
+ /// Calculates the offset from a mutable pointer.
205
+ #[ inline( always) ]
206
+ pure fn offset ( count : uint ) -> * mut T { mut_offset ( self , count) }
207
+ }
208
+
194
209
// Equality for pointers
195
210
impl < T > * const T : Eq {
196
211
pure fn eq ( other : & * const T ) -> bool unsafe {
@@ -311,4 +326,12 @@ pub fn test_is_null() {
311
326
let q = ptr:: offset ( p, 1 u) ;
312
327
assert !q. is_null ( ) ;
313
328
assert q. is_not_null ( ) ;
329
+
330
+ let mp: * mut int = ptr:: mut_null ( ) ;
331
+ assert mp. is_null ( ) ;
332
+ assert !mp. is_not_null ( ) ;
333
+
334
+ let mq = mp. offset ( 1 u) ;
335
+ assert !mq. is_null ( ) ;
336
+ assert mq. is_not_null ( ) ;
314
337
}
0 commit comments