Skip to content

Commit f03ed73

Browse files
committed
libcore: Add ptr::to_mut_unsafe_ptr
1 parent 1397c83 commit f03ed73

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/libcore/ptr.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
export addr_of;
44
export to_unsafe_ptr;
5+
export to_mut_unsafe_ptr;
56
export mut_addr_of;
67
export offset;
78
export const_offset;
@@ -132,14 +133,22 @@ unsafe fn memset<T>(dst: *mut T, c: int, count: uint) {
132133
Transform a region pointer - &T - to an unsafe pointer - *T.
133134
This is safe, but is implemented with an unsafe block due to
134135
reinterpret_cast.
135-
136-
("assimilate" because it makes the pointer forget its region.)
137136
*/
138137
#[inline(always)]
139138
fn to_unsafe_ptr<T>(thing: &T) -> *T unsafe {
140139
unsafe::reinterpret_cast(&thing)
141140
}
142141

142+
/**
143+
Transform a mutable region pointer - &mut T - to a mutable unsafe pointer -
144+
*mut T. This is safe, but is implemented with an unsafe block due to
145+
reinterpret_cast.
146+
*/
147+
#[inline(always)]
148+
fn to_mut_unsafe_ptr<T>(thing: &mut T) -> *mut T unsafe {
149+
unsafe::reinterpret_cast(thing)
150+
}
151+
143152
/**
144153
Cast a region pointer - &T - to a uint.
145154
This is safe, but is implemented with an unsafe block due to

0 commit comments

Comments
 (0)