Unsafe operations
SliceRepr
VecRepr
- The internal representation of a (boxed) vectorbuf_as_slice
- Form a slice from a pointer and length (as a number of units, not bytes).from_buf_raw
- Constructs a vector from an unsafe pointer to a bufferget
- Unchecked vector indexing.init_elem
- Unchecked vector index assignmentmemcpy
- Copies data from one vector to another.memmove
- Copies data from one vector to another.set_len
- Sets the length of a vectorto_const_ptr
- see to_ptr()
to_mut_ptr
- see to_ptr()
to_ptr
- Returns an unsafe pointer to the vector's bufferSliceRepr
type SliceRepr = {mut data: *u8, mut len: uint,}
VecRepr
pub struct VecRepr {
box_header: managed::raw::BoxHeaderRepr,
unboxed: UnboxedVecRepr,
}
The internal representation of a (boxed) vector
buf_as_slice
fn buf_as_slice<T, U>(p: *T, len: uint, f: &fn(v: &[T]) -> U) -> U
Form a slice from a pointer and length (as a number of units, not bytes).
from_buf_raw
fn from_buf_raw<T>(ptr: *T, elts: uint) -> ~[T]
Constructs a vector from an unsafe pointer to a buffer
T
get
fn get<T: Copy>(v: &[const T], i: uint) -> T
Unchecked vector indexing.
init_elem
fn init_elem<T>(v: &[mut T], i: uint, val: T)
Unchecked vector index assignment. Does not drop the old value and hence is only suitable when the vector is newly allocated.
memcpy
fn memcpy<T>(dst: &[mut T], src: &[const T], count: uint)
Copies data from one vector to another.
Copies count
bytes from src
to dst
. The source and destination may overlap.
memmove
fn memmove<T>(dst: &[mut T], src: &[const T], count: uint)
Copies data from one vector to another.
Copies count
bytes from src
to dst
. The source and destination may overlap.
set_len
fn set_len<T>(v: &mut ~[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_const_ptr
fn to_const_ptr<T>(v: &[const T]) -> *const T
see to_ptr()
to_mut_ptr
fn to_mut_ptr<T>(v: &[mut T]) -> *mut T
see to_ptr()
to_ptr
fn to_ptr<T>(v: &[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.