Skip to content

Commit

Permalink
core: Add vec::raw::mut_buf_as_slice
Browse files Browse the repository at this point in the history
  • Loading branch information
brson committed Mar 11, 2013
1 parent ce24ebb commit c88ce30
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/libcore/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down

0 comments on commit c88ce30

Please sign in to comment.