Skip to content

Commit

Permalink
auto merge of rust-lang#5305 : brson/rust/mut_buf_as_slice, r=brson
Browse files Browse the repository at this point in the history
r?

Like `buf_as_slice` but for mutable pointers and slices.
  • Loading branch information
bors committed Mar 11, 2013
2 parents e9a0db6 + c88ce30 commit 878a310
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 878a310

Please sign in to comment.