[][src]Struct gap_vec::GapVec

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

A contiguous growable array type with heap-allocated contens and gap. It's written GapVec<T> but pronounced 'gap vector'.

Examples

You can explicitly create a GapVec<T> with new :

use gap_vec::GapVec;

let v: GapVec<i32> = GapVec::new();

Methods

impl<T> GapVec<T>[src]

pub const fn new() -> GapVec<T>[src]

Constructs a new, empty GapVec<T>.

The gap vector will not allocate until elements are pushed onto it.

Examples

use gap_vec::GapVec;

let mut gap_vec: GapVec<i32> = GapVec::new();

pub fn with_capacity(capacity: usize) -> GapVec<T>[src]

Constructs a new, empty GapVec<T> with the specified capacity.

The gap vector will be able to hold exactly capacity elements without reallocating. If capacity is 0, the gap vector will not allocate.

It is important to note that although the returned gap vector has the capacity specified, the vector will have a zero length.

Examples

use gap_vec::GapVec;

let mut gap_vec = GapVec::with_capacity(10);

// These are all done without reallocating
for i in 0..10 {
    gap_vec.insert(i);
}

// ,but this may make the gap vector reallocate.
gap_vec.insert(10);

assert!(gap_vec.capacity() >= 11);

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

Returns the number of elements the gap vector can hold without reallocating.

Examples

use gap_vec::GapVec;

let gap_vec: GapVec<i32> = GapVec::with_capacity(10);
assert_eq!(gap_vec.capacity(), 10);

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

Returns the number of elements the gap vector currently holds.

Examples

use gap_vec::GapVec;

let mut gap_vec: GapVec<i32> = GapVec::with_capacity(10);
assert_eq!(gap_vec.len(), 10);

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

Returns the current the gap insertion position.

Examples

use gap_vec::GapVec;

let gap_vec: GapVec<i32> = GapVec::new();
assert_eq!(gap_vec.position(), 0);

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

Returns a reference to the index'th element, or None if index is out of bounds.

pub fn set_position(&mut self, pos: usize)[src]

Sets the current insertion position to pos.

Panics

Panics if pos > len.

pub fn insert(&mut self, element: T)[src]

Inserts an element at gap start within the gap vector.

Examples

use gap_vec::GapVec;

let mut gap_vec = GapVec::new();
gap_vec.insert("foo".to_string());
gap_vec.set_position(0);
assert_eq!(gap_vec.remove().unwrap(), "foo".to_string());

pub fn insert_iter<I>(&mut self, iterable: I) where
    I: IntoIterator<Item = T>, 
[src]

Inserts the elements produced by iter at the current insertion position, and leave the insertion position after them.

Examples

use gap_vec::GapVec;

let mut gap_vec: GapVec<char> = GapVec::new();
gap_vec.insert_iter("Foo bar baz qux quux.".chars());
assert_eq!(gap_vec.get_string(), "Foo bar baz qux quux.");

pub fn remove(&mut self) -> Option<T>[src]

Removes and returns the element at gap end within the gap vector,

Examples

use gap_vec::GapVec;

let mut gap_vec: GapVec<i32> = GapVec::new();
gap_vec.insert(3);
gap_vec.set_position(0);
assert_eq!(gap_vec.remove().unwrap(), 3);

impl GapVec<char>[src]

pub fn get_string(&self) -> String[src]

Trait Implementations

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

impl<'a, T: 'a> IntoIterator for &'a GapVec<T>[src]

type Item = &'a T

The type of the elements being iterated over.

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?

impl<T> DerefMut for GapVec<T>[src]

impl<T: Debug> Debug for GapVec<T>[src]

impl<T> Deref for GapVec<T>[src]

type Target = [T]

The resulting type after dereferencing.

Auto Trait Implementations

impl<T> Send for GapVec<T> where
    T: Send

impl<T> Sync for GapVec<T> where
    T: Sync

Blanket Implementations

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

impl<T> From for T[src]

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

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

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

The type returned in the event of a conversion error.

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