[][src]Struct c_vec::CSliceMut

pub struct CSliceMut<'a, T> { /* fields omitted */ }

The type representing an 'unsafe' mutable foreign chunk of memory.

Example

use c_vec::CSliceMut;

let slice = &mut [0, 1, 2];
let ptr = slice.as_mut_ptr();
let cslice = unsafe { CSliceMut::new(ptr, slice.len()) };

Implementations

impl<'a, T> CSliceMut<'a, T>[src]

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

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

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

Arguments

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

Example

use c_vec::CSliceMut;

let slice = &mut [0, 1, 2];
let ptr = slice.as_mut_ptr();
let cslice = unsafe { CSliceMut::new(ptr, slice.len()) };

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

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

Example

use c_vec::CSliceMut;

let slice = &mut [0, 1, 2];
let ptr = slice.as_mut_ptr();
let cslice = unsafe { CSliceMut::new(ptr, slice.len()) };
assert_eq!(cslice.get(1), slice.get(1));

pub unsafe fn get_unchecked(&self, ofs: usize) -> &T[src]

Returns a reference to an element without doing any check.

Example

use c_vec::CSliceMut;

let slice = &mut [0, 1, 2];
let ptr = slice.as_mut_ptr();
let cslice = unsafe { CSliceMut::new(ptr, slice.len()) };
unsafe {
    assert_eq!(cslice.get_unchecked(1), slice.get_unchecked(1));
}

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

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

Example

use c_vec::CSliceMut;

let slice = &mut [0, 1, 2];
let ptr = slice.as_mut_ptr();
let mut cslice = unsafe { CSliceMut::new(ptr, slice.len()) };
if let Some(el) = cslice.get_mut(1) {
    *el += 10;
}
assert_eq!(cslice[1], 11);

pub unsafe fn get_unchecked_mut(&mut self, ofs: usize) -> &mut T[src]

Returns a mutable reference to an element without doing any check.

Example

use c_vec::CSliceMut;

let slice = &mut [0, 1, 2];
let ptr = slice.as_mut_ptr();
let mut cslice = unsafe { CSliceMut::new(ptr, slice.len()) };
unsafe { *cslice.get_unchecked_mut(1) += 10; }
assert_eq!(cslice[1], 11);

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

Returns the number of items in this slice.

Example

use c_vec::CSliceMut;

let slice = &mut [0, 1, 2];
let ptr = slice.as_mut_ptr();
let cslice = unsafe { CSliceMut::new(ptr, slice.len()) };
assert_eq!(cslice.len(), slice.len());

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

Returns whether this slice is empty.

Example

use c_vec::CSliceMut;

let slice = &mut [0, 1, 2];
let ptr = slice.as_mut_ptr();
let cslice = unsafe { CSliceMut::new(ptr, slice.len()) };
assert_eq!(cslice.is_empty(), slice.is_empty());

pub fn iter<'b>(&'b self) -> CSliceMutIter<'a, 'b, T>

Notable traits for CSliceMutIter<'a, 'b, T>

impl<'a, 'b, T> Iterator for CSliceMutIter<'a, 'b, T> type Item = &'b T;
[src]

Returns an iterator over CSliceMut.

Example

use c_vec::CSliceMut;

let slice = &mut [0, 1, 2];
let ptr = slice.as_mut_ptr();
let cslice = unsafe { CSliceMut::new(ptr, slice.len()) };
for elem in cslice.iter() {
    println!("=> {}", elem);
}

pub fn iter_mut<'b>(&'b mut self) -> CSliceMutIterMut<'a, 'b, T>

Notable traits for CSliceMutIterMut<'a, 'b, T>

impl<'a, 'b, T> Iterator for CSliceMutIterMut<'a, 'b, T> type Item = &'b mut T;
[src]

Returns a mutable iterator over CSliceMut.

Example

use c_vec::CSliceMut;

let slice = &mut [0, 1, 2];
let ptr = slice.as_mut_ptr();
let mut cslice = unsafe { CSliceMut::new(ptr, slice.len()) };
for elem in cslice.iter_mut() {
    *elem += 1;
}
assert_eq!(cslice[0], 1);

Trait Implementations

impl<'a, T> AsMut<[T]> for CSliceMut<'a, T>[src]

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

View the stored data as a slice.

impl<'a, T> AsRef<[T]> for CSliceMut<'a, T>[src]

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

View the stored data as a slice.

impl<'a, T> Index<usize> for CSliceMut<'a, T>[src]

type Output = T

The returned type after indexing.

impl<'a, T> IndexMut<usize> for CSliceMut<'a, T>[src]

impl<'a, T: Clone> Into<Vec<T>> for CSliceMut<'a, T>[src]

Auto Trait Implementations

impl<'a, T> RefUnwindSafe for CSliceMut<'a, T> where
    T: RefUnwindSafe

impl<'a, T> !Send for CSliceMut<'a, T>

impl<'a, T> !Sync for CSliceMut<'a, T>

impl<'a, T> Unpin for CSliceMut<'a, T>

impl<'a, T> UnwindSafe for CSliceMut<'a, T> where
    T: RefUnwindSafe

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.