@@ -122,6 +122,54 @@ impl Map<String, Value> {
122122 return self . map . remove ( key) ;
123123 }
124124
125+ /// Removes a key from the map, returning the stored key and value if the
126+ /// key was previously in the map.
127+ ///
128+ /// The key may be any borrowed form of the map's key type, but the ordering
129+ /// on the borrowed form *must* match the ordering on the key type.
130+ pub fn remove_entry < Q > ( & mut self , key : & Q ) -> Option < ( String , Value ) >
131+ where
132+ String : Borrow < Q > ,
133+ Q : ?Sized + Ord + Eq + Hash ,
134+ {
135+ #[ cfg( any( feature = "preserve_order" , not( no_btreemap_remove_entry) ) ) ]
136+ return self . map . remove_entry ( key) ;
137+ #[ cfg( all(
138+ not( feature = "preserve_order" ) ,
139+ no_btreemap_remove_entry,
140+ not( no_btreemap_get_key_value) ,
141+ ) ) ]
142+ {
143+ let ( key, _value) = self . map . get_key_value ( key) ?;
144+ let key = key. clone ( ) ;
145+ let value = self . map . remove :: < String > ( & key) ?;
146+ Some ( ( key, value) )
147+ }
148+ #[ cfg( all(
149+ not( feature = "preserve_order" ) ,
150+ no_btreemap_remove_entry,
151+ no_btreemap_get_key_value,
152+ ) ) ]
153+ {
154+ struct Key < ' a , Q : ?Sized > ( & ' a Q ) ;
155+
156+ impl < ' a , Q : ?Sized > RangeBounds < Q > for Key < ' a , Q > {
157+ fn start_bound ( & self ) -> Bound < & Q > {
158+ Bound :: Included ( self . 0 )
159+ }
160+ fn end_bound ( & self ) -> Bound < & Q > {
161+ Bound :: Included ( self . 0 )
162+ }
163+ }
164+
165+ let mut range = self . map . range ( Key ( key) ) ;
166+ let ( key, _value) = range. next ( ) ?;
167+ let key = key. clone ( ) ;
168+ let value = self . map . remove :: < String > ( & key) ?;
169+ Some ( ( key, value) )
170+ }
171+ }
172+
125173 /// Moves all elements from other into Self, leaving other empty.
126174 #[ inline]
127175 pub fn append ( & mut self , other : & mut Self ) {
0 commit comments