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_bytes,
|
||||||
as_buf,
|
as_buf,
|
||||||
as_c_str,
|
as_c_str,
|
||||||
|
unpack_slice,
|
||||||
|
|
||||||
// Adding things to and removing things from a string
|
// Adding things to and removing things from a string
|
||||||
push_char,
|
push_char,
|
||||||
|
@ -71,6 +71,7 @@ export permute;
|
|||||||
export windowed;
|
export windowed;
|
||||||
export as_buf;
|
export as_buf;
|
||||||
export as_mut_buf;
|
export as_mut_buf;
|
||||||
|
export unpack_slice;
|
||||||
export unsafe;
|
export unsafe;
|
||||||
export u8;
|
export u8;
|
||||||
export extensions;
|
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)
|
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"]
|
#[doc = "Extension methods for vectors"]
|
||||||
impl extensions<T> for [const T] {
|
impl extensions<T> for [const T] {
|
||||||
#[doc = "
|
#[doc = "
|
||||||
|
Loading…
Reference in New Issue
Block a user