Add vec::unpack_slice, expose str::unpack_slice.
This commit is contained in:
parent
14d0509691
commit
43061f3969
@ -20,6 +20,7 @@ export
|
||||
as_bytes,
|
||||
as_buf,
|
||||
as_c_str,
|
||||
unpack_slice,
|
||||
|
||||
// Adding things to and removing things from a string
|
||||
push_char,
|
||||
|
@ -71,6 +71,7 @@ export permute;
|
||||
export windowed;
|
||||
export as_buf;
|
||||
export as_mut_buf;
|
||||
export unpack_slice;
|
||||
export unsafe;
|
||||
export u8;
|
||||
export extensions;
|
||||
@ -954,6 +955,15 @@ fn as_mut_buf<E,T>(v: [mut E], f: fn(*mut E) -> T) -> T unsafe {
|
||||
let buf = unsafe::to_ptr(v) as *mut E; f(buf)
|
||||
}
|
||||
|
||||
#[doc = "
|
||||
Work with the buffer and length of a slice.
|
||||
"]
|
||||
fn unpack_slice<T,U>(s: [const T]/&, f: fn(*T, uint) -> U) -> U unsafe {
|
||||
let v : *(*T,uint) = ::unsafe::reinterpret_cast(ptr::addr_of(s));
|
||||
let (buf,len) = *v;
|
||||
f(buf, len / sys::size_of::<T>())
|
||||
}
|
||||
|
||||
#[doc = "Extension methods for vectors"]
|
||||
impl extensions<T> for [const T] {
|
||||
#[doc = "
|
||||
|
Loading…
Reference in New Issue
Block a user