Skip to content

Commit

Permalink
Add vec::unpack_slice, expose str::unpack_slice.
Browse files Browse the repository at this point in the history
  • Loading branch information
graydon committed Apr 21, 2012
1 parent 14d0509 commit 43061f3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/libcore/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions src/libcore/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export permute;
export windowed;
export as_buf;
export as_mut_buf;
export unpack_slice;
export unsafe;
export u8;
export extensions;
Expand Down Expand Up @@ -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 = "
Expand Down

0 comments on commit 43061f3

Please sign in to comment.