[][src]Struct c_vec::CVec

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

The type representing a foreign chunk of memory.

Methods

impl<T> CVec<T>[src]

pub unsafe fn new(base: *mut T, len: usize) -> CVec<T>[src]

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

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

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.

pub fn get<'a>(&'a self, ofs: usize) -> Option<&'a T>[src]

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

pub fn get_mut<'a>(&'a mut self, ofs: usize) -> Option<&'a mut T>[src]

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

pub unsafe fn into_inner(self) -> *mut T[src]

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

pub fn len(&self) -> usize[src]

Returns the number of items in this vector.

pub fn is_empty(&self) -> bool[src]

Returns whether this vector is empty.

pub unsafe fn as_cslice(&self) -> CSlice<T>[src]

Converts to CSlice.

pub fn iter<'a>(&'a self) -> CVecIter<'a, T>[src]

Returns an iterator over CVec.

Trait Implementations

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

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

View the stored data as a slice.

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

fn as_ref(&self) -> &[T][src]

View the stored data as a slice.

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

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

Auto Trait Implementations

impl<T> !RefUnwindSafe for CVec<T>

impl<T> !Send for CVec<T>

impl<T> !Sync for CVec<T>

impl<T> Unpin for CVec<T>

impl<T> !UnwindSafe for CVec<T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.