Skip to content

Commit 43061f3

Browse files
committed
Add vec::unpack_slice, expose str::unpack_slice.
1 parent 14d0509 commit 43061f3

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/libcore/str.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export
2020
as_bytes,
2121
as_buf,
2222
as_c_str,
23+
unpack_slice,
2324

2425
// Adding things to and removing things from a string
2526
push_char,

src/libcore/vec.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export permute;
7171
export windowed;
7272
export as_buf;
7373
export as_mut_buf;
74+
export unpack_slice;
7475
export unsafe;
7576
export u8;
7677
export extensions;
@@ -954,6 +955,15 @@ fn as_mut_buf<E,T>(v: [mut E], f: fn(*mut E) -> T) -> T unsafe {
954955
let buf = unsafe::to_ptr(v) as *mut E; f(buf)
955956
}
956957

958+
#[doc = "
959+
Work with the buffer and length of a slice.
960+
"]
961+
fn unpack_slice<T,U>(s: [const T]/&, f: fn(*T, uint) -> U) -> U unsafe {
962+
let v : *(*T,uint) = ::unsafe::reinterpret_cast(ptr::addr_of(s));
963+
let (buf,len) = *v;
964+
f(buf, len / sys::size_of::<T>())
965+
}
966+
957967
#[doc = "Extension methods for vectors"]
958968
impl extensions<T> for [const T] {
959969
#[doc = "

0 commit comments

Comments
 (0)