pub fn insert<'a, K: Into<Key<'a>>, V: Into<Value>>(&mut self, k: K, v: V) -> Option<Value> {
        match k.into() {
            Key::BoolCap(k) => {
                if let mut v @ BooleanValue(_) = v.into() {
                    match self.bools.binary_search_by_key(&&k, |(k, _)| k) {
                        Ok(i) => {
                            std::mem::swap(&mut self.bools[i].1, &mut v);
                            Some(v)
                        }
                        Err(i) => {
                            self.bools.insert(i, (k, v));
                            None
                        }
                    }
                } else {
                    None
                }
            }
            Key::IntCap(k) => {
                if let mut v @ IntegerValue(_) = v.into() {
                    match self.ints.binary_search_by_key(&&k, |(k, _)| k) {
                        Ok(i) => {
                            std::mem::swap(&mut self.ints[i].1, &mut v);
                            Some(v)
                        }
                        Err(i) => {
                            self.ints.insert(i, (k, v));
                            None
                        }
                    }
                } else {
                    None
                }
            }
            Key::StrCap(k) => {
                if let mut v @ StringValue(_) = v.into() {
                    match self.strs.binary_search_by_key(&&k, |(k, _)| k) {
                        Ok(i) => {
                            std::mem::swap(&mut self.strs[i].1, &mut v);
                            Some(v)
                        }
                        Err(i) => {
                            self.strs.insert(i, (k, v));
                            None
                        }
                    }
                } else {
                    None
                }
            }
            Key::Name(k) => match (self.ex.get(k), v.into()) {
                (Some(BooleanValue(_)), v @ BooleanValue(_))
                | (Some(IntegerValue(_)), v @ IntegerValue(_))
                | (Some(StringValue(_)), v @ StringValue(_)) => self.ex.insert(k.to_owned(), v),
                (Some(BooleanValue(_)), v) => {
                    if let Some((i, _)) = self.ex_bools.iter().enumerate().find(|(_, ek)| ek == &k)
                    {
                        self.ex_bools.remove(i);
                    }
                    let r = self.ex.remove(k);
                    self.insert(k, v);
                    r
                }
                (Some(IntegerValue(_)), v) => {
                    if let Some((i, _)) = self.ex_nums.iter().enumerate().find(|(_, ek)| ek == &k) {
                        self.ex_nums.remove(i);
                    }
                    let r = self.ex.remove(k);
                    self.insert(k, v);
                    r
                }
                (Some(StringValue(_)), v) => {
                    if let Some((i, _)) = self.ex_strs.iter().enumerate().find(|(_, ek)| ek == &k) {
                        self.ex_strs.remove(i);
                    }
                    let r = self.ex.remove(k);
                    self.insert(k, v);
                    r
                }
                (None, v @ BooleanValue(_)) => {
                    self.ex_bools.push(k.to_owned());
                    self.ex.insert(k.to_owned(), v);
                    None
                }
                (None, v @ IntegerValue(_)) => {
                    self.ex_nums.push(k.to_owned());
                    self.ex.insert(k.to_owned(), v);
                    None
                }
                (None, v @ StringValue(_)) => {
                    self.ex_strs.push(k.to_owned());
                    self.ex.insert(k.to_owned(), v);
                    None
                }
            },
        }
    }
/// Insert or replace a value into the terminfo.
///
/// Returns the value that was replaced or `None` if inserting a new value.
///
/// The key may be a capname (as a `&str`),
///     a [`BooleanCap`](../caps/enum.BooleanCap.html),
///     an [`IntegerCap`](../caps/enum.IntegerCap.html),
///     or a [`StringCap`](../caps/enum.BooleanCap.html).
///
/// If the key is a `&str`, the function first attempts to convert it to
///     another type of key by interpreting it as a capcode or a capname.
/// Only if the key does not match a known capcode or capname will it be
///     interpreted as an extended key.
///
/// The value may be a `bool`, `i32`, `&str`, or `String`. If the key is,
///     for example, a `BooleanCap` and the value is not a `bool`, then
///     no value will be inserted, but no error will be produced.
/// It is therefore best practice to use strings as keys only when the
///     key being inserted is an extended capability, or to check
///     the key type by converting to a `Key` before inserting.
Insert or replace a value into the terminfo.
Returns the value that was replaced or `None` if inserting a new value.



If the key is a `&str`, the function first attempts to convert it to
another type of key by interpreting it as a capcode or a capname.
Only if the key does not match a known capcode or capname will it be
interpreted as an extended key.


Insert or replace a value into the terminfo . Returns the value that was replaced or ` None ` if inserting a new value . If the key is a ` &str ` the function first attempts to convert it to another type of key by interpreting it as a capcode or a capname . Only if the key does not match a known capcode or capname will it be interpreted as an extended key .
pub fn insert<'a, K: Into<Key<'a>>, V: Into<Value>>(&mut self, k: K, v: V) -> Option<Value> {
        match k.into() {
            Key::BoolCap(k) => {
                if let mut v @ BooleanValue(_) = v.into() {
                    match self.bools.binary_search_by_key(&&k, |(k, _)| k) {
                        Ok(i) => {
                            std::mem::swap(&mut self.bools[i].1, &mut v);
                            Some(v)
                        }
                        Err(i) => {
                            self.bools.insert(i, (k, v));
                            None
                        }
                    }
                } else {
                    None
                }
            }
            Key::IntCap(k) => {
                if let mut v @ IntegerValue(_) = v.into() {
                    match self.ints.binary_search_by_key(&&k, |(k, _)| k) {
                        Ok(i) => {
                            std::mem::swap(&mut self.ints[i].1, &mut v);
                            Some(v)
                        }
                        Err(i) => {
                            self.ints.insert(i, (k, v));
                            None
                        }
                    }
                } else {
                    None
                }
            }
            Key::StrCap(k) => {
                if let mut v @ StringValue(_) = v.into() {
                    match self.strs.binary_search_by_key(&&k, |(k, _)| k) {
                        Ok(i) => {
                            std::mem::swap(&mut self.strs[i].1, &mut v);
                            Some(v)
                        }
                        Err(i) => {
                            self.strs.insert(i, (k, v));
                            None
                        }
                    }
                } else {
                    None
                }
            }
            Key::Name(k) => match (self.ex.get(k), v.into()) {
                (Some(BooleanValue(_)), v @ BooleanValue(_))
                | (Some(IntegerValue(_)), v @ IntegerValue(_))
                | (Some(StringValue(_)), v @ StringValue(_)) => self.ex.insert(k.to_owned(), v),
                (Some(BooleanValue(_)), v) => {
                    if let Some((i, _)) = self.ex_bools.iter().enumerate().find(|(_, ek)| ek == &k)
                    {
                        self.ex_bools.remove(i);
                    }
                    let r = self.ex.remove(k);
                    self.insert(k, v);
                    r
                }
                (Some(IntegerValue(_)), v) => {
                    if let Some((i, _)) = self.ex_nums.iter().enumerate().find(|(_, ek)| ek == &k) {
                        self.ex_nums.remove(i);
                    }
                    let r = self.ex.remove(k);
                    self.insert(k, v);
                    r
                }
                (Some(StringValue(_)), v) => {
                    if let Some((i, _)) = self.ex_strs.iter().enumerate().find(|(_, ek)| ek == &k) {
                        self.ex_strs.remove(i);
                    }
                    let r = self.ex.remove(k);
                    self.insert(k, v);
                    r
                }
                (None, v @ BooleanValue(_)) => {
                    self.ex_bools.push(k.to_owned());
                    self.ex.insert(k.to_owned(), v);
                    None
                }
                (None, v @ IntegerValue(_)) => {
                    self.ex_nums.push(k.to_owned());
                    self.ex.insert(k.to_owned(), v);
                    None
                }
                (None, v @ StringValue(_)) => {
                    self.ex_strs.push(k.to_owned());
                    self.ex.insert(k.to_owned(), v);
                    None
                }
            },
        }
    }
pub fn insert < ' a , K : Into < Key < ' a > > , V : Into < Value > > ( & mut self , k : K , v : V ) -> Option < Value > { match k . into ( ) { Key :: BoolCap ( k ) => { if let mut v @ BooleanValue ( _ ) = v . into ( ) { match self . bools . binary_search_by_key ( & & k , | ( k , _ ) | k ) { Ok ( i ) => { std :: mem :: swap ( & mut self . bools [ i ] . 1 , & mut v ) ; Some ( v ) } Err ( i ) => { self . bools . insert ( i , ( k , v ) ) ; None } } } else { None } } Key :: IntCap ( k ) => { if let mut v @ IntegerValue ( _ ) = v . into ( ) { match self . ints . binary_search_by_key ( & & k , | ( k , _ ) | k ) { Ok ( i ) => { std :: mem :: swap ( & mut self . ints [ i ] . 1 , & mut v ) ; Some ( v ) } Err ( i ) => { self . ints . insert ( i , ( k , v ) ) ; None } } } else { None } } Key :: StrCap ( k ) => { if let mut v @ StringValue ( _ ) = v . into ( ) { match self . strs . binary_search_by_key ( & & k , | ( k , _ ) | k ) { Ok ( i ) => { std :: mem :: swap ( & mut self . strs [ i ] . 1 , & mut v ) ; Some ( v ) } Err ( i ) => { self . strs . insert ( i , ( k , v ) ) ; None } } } else { None } } Key :: Name ( k ) => match ( self . ex . get ( k ) , v . into ( ) ) { ( Some ( BooleanValue ( _ ) ) , v @ BooleanValue ( _ ) ) | ( Some ( IntegerValue ( _ ) ) , v @ IntegerValue ( _ ) ) | ( Some ( StringValue ( _ ) ) , v @ StringValue ( _ ) ) => self . ex . insert ( k . to_owned ( ) , v ) , ( Some ( BooleanValue ( _ ) ) , v ) => { if let Some ( ( i , _ ) ) = self . ex_bools . iter ( ) . enumerate ( ) . find ( | ( _ , ek ) | ek == & k ) { self . ex_bools . remove ( i ) ; } let r = self . ex . remove ( k ) ; self . insert ( k , v ) ; r } ( Some ( IntegerValue ( _ ) ) , v ) => { if let Some ( ( i , _ ) ) = self . ex_nums . iter ( ) . enumerate ( ) . find ( | ( _ , ek ) | ek == & k ) { self . ex_nums . remove ( i ) ; } let r = self . ex . remove ( k ) ; self . insert ( k , v ) ; r } ( Some ( StringValue ( _ ) ) , v ) => { if let Some ( ( i , _ ) ) = self . ex_strs . iter ( ) . enumerate ( ) . find ( | ( _ , ek ) | ek == & k ) { self . ex_strs . remove ( i ) ; } let r = self . ex . remove ( k ) ; self . insert ( k , v ) ; r } ( None , v @ BooleanValue ( _ ) ) => { self . ex_bools . push ( k . to_owned ( ) ) ; self . ex . insert ( k . to_owned ( ) , v ) ; None } ( None , v @ IntegerValue ( _ ) ) => { self . ex_nums . push ( k . to_owned ( ) ) ; self . ex . insert ( k . to_owned ( ) , v ) ; None } ( None , v @ StringValue ( _ ) ) => { self . ex_strs . push ( k . to_owned ( ) ) ; self . ex . insert ( k . to_owned ( ) , v ) ; None } } , } }
Insert or replace a value into the terminfo.
Insert or replace a value into the terminfo .
&mut self
k
K
v
V
&mut self
k
K
v
V