libcore: Add a to_slice_ptr function
This commit is contained in:
parent
81ecd272d3
commit
6e98416662
|
@ -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).
|
||||||
|
|
Loading…
Reference in a new issue