提交 6e984166 编写于 作者: P Patrick Walton

libcore: Add a to_slice_ptr function

上级 81ecd272
......@@ -1420,6 +1420,11 @@ mod unsafe {
data: u8
};
type slice_repr = {
mut data: *u8,
mut len: uint
};
/**
* Constructs a vector from an unsafe pointer to a buffer
*
......@@ -1465,6 +1470,13 @@ unsafe fn to_ptr<T>(v: ~[const T]) -> *T {
}
#[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,
* not bytes).
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册