auto merge of #5305 : brson/rust/mut_buf_as_slice, r=brson
r? Like `buf_as_slice` but for mutable pointers and slices.
This commit is contained in:
commit
878a31066d
@ -2145,6 +2145,20 @@ pub mod raw {
|
||||
f(*v)
|
||||
}
|
||||
|
||||
/**
|
||||
* Form a slice from a pointer and length (as a number of units,
|
||||
* not bytes).
|
||||
*/
|
||||
#[inline(always)]
|
||||
pub unsafe fn mut_buf_as_slice<T,U>(p: *mut T,
|
||||
len: uint,
|
||||
f: &fn(v: &mut [T]) -> U) -> U {
|
||||
let pair = (p, len * sys::nonzero_size_of::<T>());
|
||||
let v : *(&blk/mut [T]) =
|
||||
::cast::reinterpret_cast(&addr_of(&pair));
|
||||
f(*v)
|
||||
}
|
||||
|
||||
/**
|
||||
* Unchecked vector indexing.
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user