From 6e9841666285f0d928f35906a903d4a1e2aa6ffe Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 12 Jul 2012 19:44:00 -0700 Subject: [PATCH] libcore: Add a to_slice_ptr function --- src/libcore/vec.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 5f450ec8e34d..2eaaaf6751ea 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -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 @@ mod unsafe { } + #[inline(always)] + unsafe fn to_ptr_slice(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).