Skip to content

Commit 878a310

Browse files
committed
auto merge of #5305 : brson/rust/mut_buf_as_slice, r=brson
r? Like `buf_as_slice` but for mutable pointers and slices.
2 parents e9a0db6 + c88ce30 commit 878a310

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/libcore/vec.rs

+14
Original file line numberDiff line numberDiff line change
@@ -2145,6 +2145,20 @@ pub mod raw {
21452145
f(*v)
21462146
}
21472147

2148+
/**
2149+
* Form a slice from a pointer and length (as a number of units,
2150+
* not bytes).
2151+
*/
2152+
#[inline(always)]
2153+
pub unsafe fn mut_buf_as_slice<T,U>(p: *mut T,
2154+
len: uint,
2155+
f: &fn(v: &mut [T]) -> U) -> U {
2156+
let pair = (p, len * sys::nonzero_size_of::<T>());
2157+
let v : *(&blk/mut [T]) =
2158+
::cast::reinterpret_cast(&addr_of(&pair));
2159+
f(*v)
2160+
}
2161+
21482162
/**
21492163
* Unchecked vector indexing.
21502164
*/

0 commit comments

Comments
 (0)