diff options
| author | bors <bors@rust-lang.org> | 2013-03-11 14:06:50 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-03-11 14:06:50 -0700 |
| commit | 878a31066d9f5cbe7e81433c64cbd00e6b024551 (patch) | |
| tree | 08ccc638a8f36625666901408b6c54b0bedfa7ae | |
| parent | e9a0db6abd40913f3b366a62ebf0f59adac57bb6 (diff) | |
| parent | c88ce30c485b8df5f6dfa55d216c19c10cafe5dd (diff) | |
| download | rust-878a31066d9f5cbe7e81433c64cbd00e6b024551.tar.gz rust-878a31066d9f5cbe7e81433c64cbd00e6b024551.zip | |
auto merge of #5305 : brson/rust/mut_buf_as_slice, r=brson
r? Like `buf_as_slice` but for mutable pointers and slices.
| -rw-r--r-- | src/libcore/vec.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index aed98f3573e..697bfe63b18 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -2146,6 +2146,20 @@ pub mod raw { } /** + * 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. */ #[inline(always)] |
