Skip to content

Commit 6e98416

Browse files
committed
libcore: Add a to_slice_ptr function
1 parent 81ecd27 commit 6e98416

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/libcore/vec.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,6 +1420,11 @@ mod unsafe {
14201420
data: u8
14211421
};
14221422

1423+
type slice_repr = {
1424+
mut data: *u8,
1425+
mut len: uint
1426+
};
1427+
14231428
/**
14241429
* Constructs a vector from an unsafe pointer to a buffer
14251430
*
@@ -1465,6 +1470,13 @@ mod unsafe {
14651470
}
14661471

14671472

1473+
#[inline(always)]
1474+
unsafe fn to_ptr_slice<T>(v: &[const T]) -> *T {
1475+
let repr: **slice_repr = ::unsafe::reinterpret_cast(addr_of(v));
1476+
ret ::unsafe::reinterpret_cast(addr_of((**repr).data));
1477+
}
1478+
1479+
14681480
/**
14691481
* Form a slice from a pointer and length (as a number of units,
14701482
* not bytes).

0 commit comments

Comments
 (0)