Unsafe pointer utility functions
Ptr
of Ptr<T> for *T where <T>
- Extension methods for immutable pointersof Ptr<T> for *mut T where <T>
- Extension methods for mutable pointersof Eq for *const T where <T>
of Ord for *const T where <T>
of Eq for &'self const T where <'self, T: Eq>
of Ord for &'self const T where <'self, T: Ord>
addr_of
- Get an unsafe pointer to a valuearray_each
array_each_with_len
buf_len
- Return the offset of the first null pointer in buf
.const_offset
- Calculate the offset from a const pointercopy_memory
is_not_null
- Returns true if the pointer is not equal to the null pointer.is_null
- Returns true if the pointer is equal to the null pointer.mut_null
- Create an unsafe mutable null pointermut_offset
- Calculate the offset from a mut pointernull
- Create an unsafe null pointeroffset
- Calculate the offset from a pointerposition
- Return the first offset i
such that f(buf[i]) == true
.ref_eq
- Determine if two borrowed pointers point to the same thing.set_memory
to_const_unsafe_ptr
- Transform a const region pointer - &const T - to a const unsafe pointer - *const Tto_mut_unsafe_ptr
- Transform a mutable region pointer - &mut T - to a mutable unsafe pointer - *mut Tto_uint
- Cast a region pointer - &T - to a uintto_unsafe_ptr
- Transform a region pointer - &T - to an unsafe pointer - *Tptr::libc_
ptr::rusti
Ptr
is_null
fn is_null(&const self) -> bool
is_not_null
fn is_not_null(&const self) -> bool
offset
fn offset(&self, count: uint) -> Self
Ptr<T>
for *T
where <T>
Extension methods for immutable pointers
is_null
fn is_null(&const self) -> bool
Returns true if the pointer is equal to the null pointer.
is_not_null
fn is_not_null(&const self) -> bool
Returns true if the pointer is not equal to the null pointer.
offset
fn offset(&self, count: uint) -> *T
Calculates the offset from a pointer.
Ptr<T>
for *mut T
where <T>
Extension methods for mutable pointers
is_null
fn is_null(&const self) -> bool
Returns true if the pointer is equal to the null pointer.
is_not_null
fn is_not_null(&const self) -> bool
Returns true if the pointer is not equal to the null pointer.
offset
fn offset(&self, count: uint) -> *mut T
Calculates the offset from a mutable pointer.
Eq
for *const T
where <T>
eq
fn eq(&self, other: &*const T) -> bool
ne
fn ne(&self, other: &*const T) -> bool
Ord
for *const T
where <T>
lt
fn lt(&self, other: &*const T) -> bool
le
fn le(&self, other: &*const T) -> bool
ge
fn ge(&self, other: &*const T) -> bool
gt
fn gt(&self, other: &*const T) -> bool
Eq
for &'self const T
where <'self, T: Eq>
eq
fn eq(&self, other: &&'self const T) -> bool
ne
fn ne(&self, other: &&'self const T) -> bool
Ord
for &'self const T
where <'self, T: Ord>
lt
fn lt(&self, other: &&'self const T) -> bool
le
fn le(&self, other: &&'self const T) -> bool
ge
fn ge(&self, other: &&'self const T) -> bool
gt
fn gt(&self, other: &&'self const T) -> bool
addr_of
fn addr_of<T>(val: &T) -> *T
Get an unsafe pointer to a value
array_each
unsafe fn array_each<T>(arr: **T, cb: &fn(*T))
Given a null-pointer-terminated **T (pointer to an array of pointers), iterate through each *T, passing to the provided callback function
SAFETY NOTE: This will only work with a null-terminated pointer array. Barely less-dodgey Pointer Arithmetic. Dragons be here.
array_each_with_len
unsafe fn array_each_with_len<T>(arr: **T, len: uint, cb: &fn(*T))
Given a **T (pointer to an array of pointers), iterate through each *T, up to the provided len
, passing to the provided callback function
SAFETY NOTE: Pointer-arithmetic. Dragons be here.
buf_len
unsafe fn buf_len<T>(buf: **T) -> uint
Return the offset of the first null pointer in buf
.
const_offset
fn const_offset<T>(ptr: *const T, count: uint) -> *const T
Calculate the offset from a const pointer
copy_memory
unsafe fn copy_memory<T>(dst: *mut T, src: *const T, count: uint)
is_not_null
fn is_not_null<T>(ptr: *const T) -> bool
Returns true if the pointer is not equal to the null pointer.
is_null
fn is_null<T>(ptr: *const T) -> bool
Returns true if the pointer is equal to the null pointer.
mut_null
fn mut_null<T>() -> *mut T
Create an unsafe mutable null pointer
mut_offset
fn mut_offset<T>(ptr: *mut T, count: uint) -> *mut T
Calculate the offset from a mut pointer
null
fn null<T>() -> *T
Create an unsafe null pointer
offset
fn offset<T>(ptr: *T, count: uint) -> *T
Calculate the offset from a pointer
position
unsafe fn position<T>(buf: *T, f: &fn(&T) -> bool) -> uint
Return the first offset i
such that f(buf[i]) == true
.
ref_eq
fn ref_eq<'a, 'b, T>(thing: &'a T, other: &'b T) -> bool
Determine if two borrowed pointers point to the same thing.
set_memory
unsafe fn set_memory<T>(dst: *mut T, c: int, count: uint)
to_const_unsafe_ptr
fn to_const_unsafe_ptr<T>(thing: &const T) -> *const T
Transform a const region pointer - &const T - to a const unsafe pointer - *const T. This is safe, but is implemented with an unsafe block due to reinterpret_cast.
to_mut_unsafe_ptr
fn to_mut_unsafe_ptr<T>(thing: &mut T) -> *mut T
Transform a mutable region pointer - &mut T - to a mutable unsafe pointer - *mut T. This is safe, but is implemented with an unsafe block due to reinterpret_cast.
to_uint
fn to_uint<T>(thing: &T) -> uint
Cast a region pointer - &T - to a uint. This is safe, but is implemented with an unsafe block due to reinterpret_cast.
(I couldn't think of a cutesy name for this one.)
to_unsafe_ptr
fn to_unsafe_ptr<T>(thing: &T) -> *T
Transform a region pointer - &T - to an unsafe pointer - *T. This is safe, but is implemented with an unsafe block due to reinterpret_cast.