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).copy_memory
- Copies data from one vector to another.from_buf_raw
- Constructs a vector from an unsafe pointer to a bufferget
- Unchecked vector indexing.init_elem
- Unchecked vector index assignmentmut_buf_as_slice
- Form a slice from a pointer and length (as a number of units, not bytes).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
pub struct 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
unsafe 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).
copy_memory
unsafe fn copy_memory<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.
from_buf_raw
unsafe fn from_buf_raw<T>(ptr: *T, elts: uint) -> ~[T]
Constructs a vector from an unsafe pointer to a buffer
T
get
unsafe fn get<T: Copy>(v: &const [T], i: uint) -> T
Unchecked vector indexing.
init_elem
unsafe 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.
mut_buf_as_slice
unsafe fn mut_buf_as_slice<T,
U>(p: *mut T, len: uint, f: &fn(v: &mut [T]) -> U)
-> U
Form a slice from a pointer and length (as a number of units, not bytes).
set_len
unsafe 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
unsafe fn to_const_ptr<T>(v: &const [T]) -> *const T
see to_ptr()
to_mut_ptr
unsafe fn to_mut_ptr<T>(v: &mut [T]) -> *mut T
see to_ptr()
to_ptr
unsafe 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.