[−][src]Struct key_vec::KeyVec
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]
K: Ord + Clone + Debug,
V: PartialEq,
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]
R: RangeBounds<usize>,
ⓘ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) -> usize
1.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 T
1.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) -> usize
1.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) -> bool
1.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]
K: Ord + Clone + Debug,
V: PartialEq,
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]
K: Ord + Clone + Debug,
V: PartialEq,
fn extend<I: IntoIterator<Item = (K, V)>>(&mut self, iter: I)
[src]
impl<K, V> IntoIterator for KeyVec<K, V> where
K: Ord + Clone + Debug,
V: PartialEq,
[src]
K: Ord + Clone + Debug,
V: PartialEq,
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?
fn into_iter(self) -> Self::IntoIter
[src]
impl<K: Clone, V: Clone> Clone for KeyVec<K, V> where
K: Ord + Clone + Debug,
V: PartialEq,
[src]
K: Ord + Clone + Debug,
V: PartialEq,
impl<K, V> Default for KeyVec<K, V> where
K: Ord + Clone + Debug,
V: PartialEq,
[src]
K: Ord + Clone + Debug,
V: PartialEq,
impl<K: PartialEq, V: PartialEq> PartialEq<KeyVec<K, V>> for KeyVec<K, V> where
K: Ord + Clone + Debug,
V: PartialEq,
[src]
K: Ord + Clone + Debug,
V: PartialEq,
impl<K: Debug, V: Debug> Debug for KeyVec<K, V> where
K: Ord + Clone + Debug,
V: PartialEq,
[src]
K: Ord + Clone + Debug,
V: PartialEq,
impl<K, V> Deref for KeyVec<K, V> where
K: Ord + Clone + Debug,
V: PartialEq,
[src]
K: Ord + Clone + Debug,
V: PartialEq,
type Target = Vec<(K, V)>
The resulting type after dereferencing.
fn deref(&self) -> &Vec<(K, V)>
[src]
impl<K, V> StructuralPartialEq for KeyVec<K, V> where
K: Ord + Clone + Debug,
V: PartialEq,
[src]
K: Ord + Clone + Debug,
V: PartialEq,
impl<K, V> FromIterator<(K, V)> for KeyVec<K, V> where
K: Ord + Clone + Debug,
V: PartialEq,
[src]
K: Ord + Clone + Debug,
V: PartialEq,
fn from_iter<I: IntoIterator<Item = (K, V)>>(iter: I) -> Self
[src]
Auto Trait Implementations
impl<K, V> Send for KeyVec<K, V> where
K: Send,
V: Send,
K: Send,
V: Send,
impl<K, V> Sync for KeyVec<K, V> where
K: Sync,
V: Sync,
K: Sync,
V: Sync,
impl<K, V> Unpin for KeyVec<K, V> where
K: Unpin,
V: Unpin,
K: Unpin,
V: Unpin,
impl<K, V> UnwindSafe for KeyVec<K, V> where
K: UnwindSafe,
V: UnwindSafe,
K: UnwindSafe,
V: UnwindSafe,
impl<K, V> RefUnwindSafe for KeyVec<K, V> where
K: RefUnwindSafe,
V: RefUnwindSafe,
K: RefUnwindSafe,
V: RefUnwindSafe,
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
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?
fn into_iter(self) -> I
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,