pub fn insert(&self, key: K, item: V) -> Result<BtMap<K, V>, ()> {
        match self.root {
            Some(ref node) => {
                match key.cmp(&node.key) {
                    Ordering::Equal => Err(()),
                    Ordering::Less => Ok(BtMap {
                        size: self.size + 1,
                        root: Some(Rc::new(Node {
                            key: key,
                            val: item,
                            left: None,
                            right: Some(node.clone()),
                        }))
                    }),
                    Ordering::Greater => Ok(BtMap {
                        size: self.size + 1,
                        root: Some(Rc::new(Node {
                            key: key,
                            val: item,
                            left: Some(node.clone()),
                            right: None,
                        }))
                    })
                }
            },
            None => {
                Ok(BtMap {
                    size: 1,
                    root: Some(Rc::new(Node {
                        key: key,
                        val: item,
                        left: None,
                        right: None,
                    }))
                })
            }
        }
    }
/// Returns a new map containing all the items in the original map,
/// as well as the new item.  Returns an error if there is already
/// an item corresponding to the key.
Returns a new map containing all the items in the original map,
as well as the new item.  Returns an error if there is already
an item corresponding to the key.
Returns a new map containing all the items in the original map as well as the new item . Returns an error if there is already an item corresponding to the key .
pub fn insert(&self, key: K, item: V) -> Result<BtMap<K, V>, ()> {
        match self.root {
            Some(ref node) => {
                match key.cmp(&node.key) {
                    Ordering::Equal => Err(()),
                    Ordering::Less => Ok(BtMap {
                        size: self.size + 1,
                        root: Some(Rc::new(Node {
                            key: key,
                            val: item,
                            left: None,
                            right: Some(node.clone()),
                        }))
                    }),
                    Ordering::Greater => Ok(BtMap {
                        size: self.size + 1,
                        root: Some(Rc::new(Node {
                            key: key,
                            val: item,
                            left: Some(node.clone()),
                            right: None,
                        }))
                    })
                }
            },
            None => {
                Ok(BtMap {
                    size: 1,
                    root: Some(Rc::new(Node {
                        key: key,
                        val: item,
                        left: None,
                        right: None,
                    }))
                })
            }
        }
    }
pub fn insert ( & self , key : K , item : V ) -> Result < BtMap < K , V > , ( ) > { match self . root { Some ( ref node ) => { match key . cmp ( & node . key ) { Ordering :: Equal => Err ( ( ) ) , Ordering :: Less => Ok ( BtMap { size : self . size + 1 , root : Some ( Rc :: new ( Node { key : key , val : item , left : None , right : Some ( node . clone ( ) ) , } ) ) } ) , Ordering :: Greater => Ok ( BtMap { size : self . size + 1 , root : Some ( Rc :: new ( Node { key : key , val : item , left : Some ( node . clone ( ) ) , right : None , } ) ) } ) } } , None => { Ok ( BtMap { size : 1 , root : Some ( Rc :: new ( Node { key : key , val : item , left : None , right : None , } ) ) } ) } } }
Returns a new map containing all the items in the original map,
as well as the new item.
Returns a new map containing all the items in the original map as well as the new item .
&self
key
K
item
V
&self
key
K
item
V