core: Add vec::raw::mut_buf_as_slice
This commit is contained in:
parent
ce24ebb858
commit
c88ce30c48
1 changed files with 14 additions and 0 deletions
|
|
@ -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…
Add table
Add a link
Reference in a new issue