[][src]Struct key_vec::KeyVec

pub struct KeyVec<K, V> where
    K: Ord + Clone + Debug,
    V: PartialEq
{ /* fields omitted */ }

Vec of key-value pairs sorted by key.

See crate-level documentation for examples.

Methods

impl<K, V> KeyVec<K, V> where
    K: Ord + Clone + Debug,
    V: PartialEq
[src]

pub fn new() -> Self[src]

pub fn with_capacity(capacity: usize) -> Self[src]

pub fn insert(&mut self, key: K, value: V) -> Option<V>[src]

Insert an (key,value) pair, returning an existing value if one was present for the corresponding key.

pub fn get(&self, key: &K) -> Option<&V>[src]

pub fn get_mut(&mut self, key: &K) -> Option<&mut V>[src]

pub fn remove(&mut self, key: &K) -> Option<V>[src]

pub fn remove_index(&mut self, index: usize) -> (K, V)[src]

Panics if index is out of bounds

pub fn pop(&mut self) -> Option<(K, V)>[src]

pub fn clear(&mut self)[src]

pub fn drain<R>(&mut self, range: R) -> Drain<(K, V)> where
    R: RangeBounds<usize>, 
[src]

Important traits for IterMut<'a, K, V>
pub fn iter_mut(&mut self) -> IterMut<K, V>[src]

Methods from Deref<Target = Vec<(K, V)>>

pub fn capacity(&self) -> usize1.0.0[src]

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

Examples

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

pub fn as_slice(&self) -> &[T]1.7.0[src]

Extracts a slice containing the entire vector.

Equivalent to &s[..].

Examples

use std::io::{self, Write};
let buffer = vec![1, 2, 3, 5, 8];
io::sink().write(buffer.as_slice()).unwrap();

pub fn as_ptr(&self) -> *const T1.37.0[src]

Returns a raw pointer to the vector's buffer.

The caller must ensure that the vector outlives the pointer this function returns, or else it will end up pointing to garbage. Modifying the vector may cause its buffer to be reallocated, which would also make any pointers to it invalid.

The caller must also ensure that the memory the pointer (non-transitively) points to is never written to (except inside an UnsafeCell) using this pointer or any pointer derived from it. If you need to mutate the contents of the slice, use as_mut_ptr.

Examples

let x = vec![1, 2, 4];
let x_ptr = x.as_ptr();

unsafe {
    for i in 0..x.len() {
        assert_eq!(*x_ptr.add(i), 1 << i);
    }
}

pub fn len(&self) -> usize1.0.0[src]

Returns the number of elements in the vector, also referred to as its 'length'.

Examples

let a = vec![1, 2, 3];
assert_eq!(a.len(), 3);

pub fn is_empty(&self) -> bool1.0.0[src]

Returns true if the vector contains no elements.

Examples

let mut v = Vec::new();
assert!(v.is_empty());

v.push(1);
assert!(!v.is_empty());

Trait Implementations

impl<K, V> From<Vec<(K, V)>> for KeyVec<K, V> where
    K: Ord + Clone + Debug,
    V: PartialEq
[src]

fn from(vec: Vec<(K, V)>) -> Self[src]

Uses sort_by_key() and dedup_by_key() to remove duplicate key entries.

Note that dedup_by_key() will keep the first of duplicate keys present in the input vector.

impl<K, V> Extend<(K, V)> for KeyVec<K, V> where
    K: Ord + Clone + Debug,
    V: PartialEq
[src]

impl<K, V> IntoIterator for KeyVec<K, V> where
    K: Ord + Clone + Debug,
    V: PartialEq
[src]

type Item = (K, V)

The type of the elements being iterated over.

type IntoIter = IntoIter<Self::Item>

Which kind of iterator are we turning this into?

impl<K: Clone, V: Clone> Clone for KeyVec<K, V> where
    K: Ord + Clone + Debug,
    V: PartialEq
[src]

impl<K, V> Default for KeyVec<K, V> where
    K: Ord + Clone + Debug,
    V: PartialEq
[src]

impl<K: PartialEq, V: PartialEq> PartialEq<KeyVec<K, V>> for KeyVec<K, V> where
    K: Ord + Clone + Debug,
    V: PartialEq
[src]

impl<K: Debug, V: Debug> Debug for KeyVec<K, V> where
    K: Ord + Clone + Debug,
    V: PartialEq
[src]

impl<K, V> Deref for KeyVec<K, V> where
    K: Ord + Clone + Debug,
    V: PartialEq
[src]

type Target = Vec<(K, V)>

The resulting type after dereferencing.

impl<K, V> StructuralPartialEq for KeyVec<K, V> where
    K: Ord + Clone + Debug,
    V: PartialEq
[src]

impl<K, V> FromIterator<(K, V)> for KeyVec<K, V> where
    K: Ord + Clone + Debug,
    V: PartialEq
[src]

Auto Trait Implementations

impl<K, V> Send for KeyVec<K, V> where
    K: Send,
    V: Send

impl<K, V> Sync for KeyVec<K, V> where
    K: Sync,
    V: Sync

impl<K, V> Unpin for KeyVec<K, V> where
    K: Unpin,
    V: Unpin

impl<K, V> UnwindSafe for KeyVec<K, V> where
    K: UnwindSafe,
    V: UnwindSafe

impl<K, V> RefUnwindSafe for KeyVec<K, V> where
    K: RefUnwindSafe,
    V: RefUnwindSafe

Blanket Implementations

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

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

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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.

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

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

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