Unsafe operations
vec_repr
- The internal representation of a vectorform_slice
- Form a slice from a pointer and length (as a number of units, not bytes).from_buf
- Constructs a vector from an unsafe pointer to a bufferset_len
- Sets the length of a vectorto_ptr
- Returns an unsafe pointer to the vector's buffervec_repr
type vec_repr = {box_header: (uint, uint, uint, uint),
mut fill: uint,
mut alloc: uint,
data: u8,}
The internal representation of a vector
form_slice
unsafe fn form_slice<T, U>(p: *T, len: uint, f: fn(&&& [T]) -> U) -> U
Form a slice from a pointer and length (as a number of units, not bytes).
from_buf
unsafe fn from_buf<T>(ptr: *T, elts: uint) -> ~[T]
Constructs a vector from an unsafe pointer to a buffer
T
set_len
unsafe fn set_len<T>(&&v: ~[const T], new_len: uint)
Sets the length of a vector
This will explicitly set the size of the vector, without actually modifing its buffers, so it is up to the caller to ensure that the vector is actually the specified size.
to_ptr
unsafe fn to_ptr<T>(v: ~[const T]) -> *T
Returns an unsafe pointer to the vector's buffer
The caller must ensure that the vector outlives the pointer this function returns, or else it will end up pointing to garbage.
Modifying the vector may cause its buffer to be reallocated, which would also make any pointers to it invalid.