Unsafe operations

Type SliceRepr

type SliceRepr = {mut data: *u8, mut len: uint,}

Struct VecRepr

pub struct VecRepr {
    box_header: managed::raw::BoxHeaderRepr,
    unboxed: UnboxedVecRepr,
}

The internal representation of a (boxed) vector

Function 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).

Function from_buf_raw

fn from_buf_raw<T>(ptr: *T, elts: uint) -> ~[T]

Constructs a vector from an unsafe pointer to a buffer

Arguments

Function get

fn get<T: Copy>(v: &[const T], i: uint) -> T

Unchecked vector indexing.

Function 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.

Function 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.

Function 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.

Function 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.

Function to_const_ptr

fn to_const_ptr<T>(v: &[const T]) -> *const T

see to_ptr()

Function to_mut_ptr

fn to_mut_ptr<T>(v: &[mut T]) -> *mut T

see to_ptr()

Function 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.