libcore: Add a to_slice_ptr function

This commit is contained in:
Patrick Walton 2012-07-12 19:44:00 -07:00
parent 81ecd272d3
commit 6e98416662

View file

@ -1420,6 +1420,11 @@ mod unsafe {
data: u8 data: u8
}; };
type slice_repr = {
mut data: *u8,
mut len: uint
};
/** /**
* Constructs a vector from an unsafe pointer to a buffer * Constructs a vector from an unsafe pointer to a buffer
* *
@ -1465,6 +1470,13 @@ mod unsafe {
} }
#[inline(always)]
unsafe fn to_ptr_slice<T>(v: &[const T]) -> *T {
let repr: **slice_repr = ::unsafe::reinterpret_cast(addr_of(v));
ret ::unsafe::reinterpret_cast(addr_of((**repr).data));
}
/** /**
* Form a slice from a pointer and length (as a number of units, * Form a slice from a pointer and length (as a number of units,
* not bytes). * not bytes).