# Struct c_vec::CVec [−] [src]

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

The type representing a foreign chunk of memory

## Methods

### `impl<T> CVec<T>`
[src]

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

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

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

# Arguments

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

#### `unsafe fn new_with_dtor<F>(base: *mut T, len: usize, dtor: F) -> CVec<T> where
F: FnMut(*mut T) + 'static,`

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

Panics if the given pointer is null.

# Arguments

- base - A unique pointer to a buffer
- len - The number of elements in the buffer
- dtor - A fn to run when the value is destructed, useful for freeing the buffer, etc. `base` will be passed to it as an argument.

#### `fn get<'a>(&'a self, ofs: usize) -> 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: usize) -> 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 into_inner(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)`.

#### `fn len(&self) -> usize`

Returns the number of items in this vector.

#### `fn is_empty(&self) -> bool`

Returns whether this vector is empty.

#### `fn as_cslice(&self) -> CSlice<T>`

Convert to CSlice

## Trait Implementations

### `impl<T> Drop for CVec<T>`
[src]

#### `fn drop(&mut self)`

A method called when the value goes out of scope. Read more

### `impl<T> AsRef<[T]> for CVec<T>`
[src]

#### `fn as_ref(&self) -> &[T]`

View the stored data as a slice.

### `impl<T> AsMut<[T]> for CVec<T>`
[src]

#### `fn as_mut(&mut self) -> &mut [T]`

View the stored data as a slice.

### `impl<T: Clone> Into<Vec<T>> for CVec<T>`
[src]

#### `fn into(self: CVec<T>) -> Vec<T>`

Performs the conversion.

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
⇤
  Move up in search results
⇥
  Move down in search results
⏎
  Go to active search result
+
  Collapse/expand all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)