pub fn insert_or_replace(&mut self, key: K, value: V) -> Option<V>
    where
        K: PartialEq,
    {
        match get_last_index(&self.entries, &key) {
            None => {
                self.insert(key, value);
                None
            }
            Some(idx) => {
                let mut entry = (key, value);
                std::mem::swap(&mut self.entries[idx], &mut entry);
                Some(entry.1)
            }
        }
    }
/// Insert the given key-value pair into the association list.
///
/// If one entry with the given key already exists in the list, it will be
/// removed, and its value will be returned. If multiple entries with the
/// given key already exist in the list, only the most recently inserted one
/// will be removed.
///
/// # Examples
///
/// ```
/// use bumpalo::Bump;
/// use arena_collections::AssocListMut;
///
/// let b = Bump::new();
/// let mut alist = AssocListMut::new_in(&b);
/// alist.insert_or_replace(1, "a");
/// assert_eq!(alist.get(&1), Some(&"a"));
/// alist.insert_or_replace(1, "b");
/// assert_eq!(alist.get(&1), Some(&"b"));
/// assert_eq!(alist.len(), 1);
/// ```
Insert the given key-value pair into the association list.
If one entry with the given key already exists in the list, it will be
removed, and its value will be returned. If multiple entries with the
given key already exist in the list, only the most recently inserted one
will be removed.
Insert the given key - value pair into the association list . If one entry with the given key already exists in the list it will be removed and its value will be returned . If multiple entries with the given key already exist in the list only the most recently inserted one will be removed .
pub fn insert_or_replace(&mut self, key: K, value: V) -> Option<V>
    where
        K: PartialEq,
    {
        match get_last_index(&self.entries, &key) {
            None => {
                self.insert(key, value);
                None
            }
            Some(idx) => {
                let mut entry = (key, value);
                std::mem::swap(&mut self.entries[idx], &mut entry);
                Some(entry.1)
            }
        }
    }
pub fn insert_or_replace ( & mut self , key : K , value : V ) -> Option < V > where K : PartialEq , { match get_last_index ( & self . entries , & key ) { None => { self . insert ( key , value ) ; None } Some ( idx ) => { let mut entry = ( key , value ) ; std :: mem :: swap ( & mut self . entries [ idx ] , & mut entry ) ; Some ( entry . 1 ) } } }
Insert the given key-value pair into the association list.
Insert the given key - value pair into the association list .
&mut self
key
K
value
V
&mut self
key
K
value
V
examples
```
use bumpalo::Bump;
use arena_collections::AssocListMut.


` ` ` use bumpalo :: Bump ; use arena_collections :: AssocListMut .