Unsafe operations

Struct SliceRepr

pub struct SliceRepr {
    /// Pointer to the base of this slice
    data: *u8,
    /// The length of the slice
    len: uint,
}

The internal representation of a slice

Struct VecRepr

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

The internal representation of a (boxed) vector

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

Function copy_memory

unsafe fn copy_memory<T>(dst: &mut [T], src: &[T], count: uint)

Copies data from one vector to another.

Copies count bytes from src to dst. The source and destination may overlap.

Function from_buf_raw

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

Constructs a vector from an unsafe pointer to a buffer

Arguments

Function get

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

Unchecked vector indexing.

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

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

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

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.