mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-29 20:46:07 +03:00
core: Add vec::raw::mut_buf_as_slice
This commit is contained in:
@@ -2145,6 +2145,20 @@ pub unsafe fn buf_as_slice<T,U>(p: *T,
|
||||
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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user