(See stabilization tracking thread for feature(map_try_insert) here)
HashMap::insert and BTreeMap::insert take a key,value by value.
Meaning that once insert is called, we can no longer access the key.
This prevents us from including the offending key in the message of a DuplidateDictionaryKey error.
Note that insert will return you the old value (in the case of a duplicate), but not the old key.
However, there is a new try_insert function on nightly rust which unlike insert (which will always replace an existing entry), try_insert will fail with an Err if the key is already present. And the returned Err includes both the key and value.
When this function is stabilized, we should update our dictionary decoding to take advantage of it.
(See stabilization tracking thread for
feature(map_try_insert)here)HashMap::insertandBTreeMap::inserttake akey,valueby value.Meaning that once
insertis called, we can no longer access the key.This prevents us from including the offending key in the message of a
DuplidateDictionaryKeyerror.Note that
insertwill return you the old value (in the case of a duplicate), but not the old key.However, there is a new
try_insertfunction on nightly rust which unlikeinsert(which will always replace an existing entry),try_insertwill fail with anErrif the key is already present. And the returnedErrincludes both the key and value.When this function is stabilized, we should update our dictionary decoding to take advantage of it.