diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2012-09-02 15:54:05 -0700 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2012-09-02 15:54:24 -0700 |
| commit | f03ed73c5efdd209907ad353b334a0c6cf474bc7 (patch) | |
| tree | 8de9f67814cc306b5ea389f438e3ee856e1f2fb5 /src | |
| parent | 1397c83f11c647ba6f9e1362ac551d4454682947 (diff) | |
| download | rust-f03ed73c5efdd209907ad353b334a0c6cf474bc7.tar.gz rust-f03ed73c5efdd209907ad353b334a0c6cf474bc7.zip | |
libcore: Add ptr::to_mut_unsafe_ptr
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcore/ptr.rs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 27998b49415..0117db25c58 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -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,8 +133,6 @@ 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 { @@ -141,6 +140,16 @@ fn to_unsafe_ptr<T>(thing: &T) -> *T unsafe { } /** + 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 reinterpret_cast. |
