@@ -47,23 +47,23 @@ pub pure fn mut_addr_of<T>(val: &T) -> *mut T {
47
47
48
48
/// Calculate the offset from a pointer
49
49
#[ inline( always) ]
50
- pub fn offset < T > ( ptr : * T , count : uint ) -> * T {
50
+ pub pure fn offset < T > ( ptr : * T , count : uint ) -> * T {
51
51
unsafe {
52
52
( ptr as uint + count * sys:: size_of :: < T > ( ) ) as * T
53
53
}
54
54
}
55
55
56
56
/// Calculate the offset from a const pointer
57
57
#[ inline( always) ]
58
- pub fn const_offset < T > ( ptr : * const T , count : uint ) -> * const T {
58
+ pub pure fn const_offset < T > ( ptr : * const T , count : uint ) -> * const T {
59
59
unsafe {
60
60
( ptr as uint + count * sys:: size_of :: < T > ( ) ) as * T
61
61
}
62
62
}
63
63
64
64
/// Calculate the offset from a mut pointer
65
65
#[ inline( always) ]
66
- pub fn mut_offset < T > ( ptr : * mut T , count : uint ) -> * mut T {
66
+ pub pure fn mut_offset < T > ( ptr : * mut T , count : uint ) -> * mut T {
67
67
( ptr as uint + count * sys:: size_of :: < T > ( ) ) as * mut T
68
68
}
69
69
@@ -176,18 +176,25 @@ pub fn ref_eq<T>(thing: &a/T, other: &b/T) -> bool {
176
176
to_uint ( thing) == to_uint ( other)
177
177
}
178
178
179
- pub trait Ptr {
179
+ pub trait Ptr < T > {
180
180
pure fn is_null ( ) -> bool ;
181
181
pure fn is_not_null ( ) -> bool ;
182
+ pure fn offset( count : uint ) -> self ;
182
183
}
183
184
184
185
/// Extension methods for pointers
185
- impl < T > * T : Ptr {
186
+ impl < T > * T : Ptr < T > {
186
187
/// Returns true if the pointer is equal to the null pointer.
188
+ #[ inline( always) ]
187
189
pure fn is_null ( ) -> bool { is_null ( self ) }
188
190
189
191
/// Returns true if the pointer is not equal to the null pointer.
192
+ #[ inline( always) ]
190
193
pure fn is_not_null ( ) -> bool { is_not_null ( self ) }
194
+
195
+ /// Calculates the offset from a pointer.
196
+ #[ inline( always) ]
197
+ pure fn offset ( count : uint ) -> * T { offset ( self , count) }
191
198
}
192
199
193
200
// Equality for pointers
0 commit comments