libcore: Add ptr::to_mut_unsafe_ptr

This commit is contained in:
Patrick Walton 2012-09-02 15:54:05 -07:00
parent 1397c83f11
commit f03ed73c5e

View File

@ -2,6 +2,7 @@
export addr_of;
export to_unsafe_ptr;
export to_mut_unsafe_ptr;
export mut_addr_of;
export offset;
export const_offset;
@ -132,14 +133,22 @@ unsafe fn memset<T>(dst: *mut T, c: int, count: uint) {
Transform a region pointer - &T - to an unsafe pointer - *T.
This is safe, but is implemented with an unsafe block due to
reinterpret_cast.
("assimilate" because it makes the pointer forget its region.)
*/
#[inline(always)]
fn to_unsafe_ptr<T>(thing: &T) -> *T unsafe {
unsafe::reinterpret_cast(&thing)
}
/**
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.
*/
#[inline(always)]
fn to_mut_unsafe_ptr<T>(thing: &mut T) -> *mut T unsafe {
unsafe::reinterpret_cast(thing)
}
/**
Cast a region pointer - &T - to a uint.
This is safe, but is implemented with an unsafe block due to