[src]

Struct std::c_vec::CVec

pub struct CVec<T> {
    // some fields omitted
}

The type representing a foreign chunk of memory

Methods

impl<T> CVec<T>

unsafe fn new(base: *mut T, len: uint) -> CVec<T>

Create a CVec from a raw pointer to a buffer with a given length.

Fails if the given pointer is null. The returned vector will not attempt to deallocate the vector when dropped.

Arguments

  • base - A raw pointer to a buffer
  • len - The number of elements in the buffer

unsafe fn new_with_dtor(base: *mut T, len: uint, dtor: proc()) -> CVec<T>

Create a CVec from a foreign buffer, with a given length, and a function to run upon destruction.

Fails if the given pointer is null.

Arguments

  • base - A foreign pointer to a buffer
  • len - The number of elements in the buffer
  • dtor - A proc to run when the value is destructed, useful for freeing the buffer, etc.

fn as_slice<'a>(&'a self) -> &'a [T]

View the stored data as a slice.

fn as_mut_slice<'a>(&'a mut self) -> &'a mut [T]

View the stored data as a mutable slice.

fn get<'a>(&'a self, ofs: uint) -> Option<&'a T>

Retrieves an element at a given index, returning None if the requested index is greater than the length of the vector.

fn get_mut<'a>(&'a mut self, ofs: uint) -> Option<&'a mut T>

Retrieves a mutable element at a given index, returning None if the requested index is greater than the length of the vector.

unsafe fn unwrap(self) -> *mut T

Unwrap the pointer without running the destructor

This method retrieves the underlying pointer, and in the process destroys the CVec but without running the destructor. A use case would be transferring ownership of the buffer to a C function, as in this case you would not want to run the destructor.

Note that if you want to access the underlying pointer without cancelling the destructor, you can simply call transmute on the return value of get(0).

Trait Implementations

impl<T> Drop for CVec<T>

fn drop(&mut self)

The drop method, called when the value goes out of scope.

impl<T> Container for CVec<T>

fn len(&self) -> uint

Return the number of elements in the container

fn is_empty(&self) -> bool

Return true if the container contains no elements