File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed
Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -482,6 +482,21 @@ impl JsonValue {
482482 }
483483 }
484484
485+ /// Works on `JsonValue::Object` - inserts a new entry, or override an existing
486+ /// one into the object. Note that `key` has to be a `&str` slice and not an owned
487+ /// `String`. The internals of `Object` will handle the heap allocation of the key
488+ /// if needed for better performance.
489+ pub fn insert < T > ( & mut self , key : & str , value : T ) -> Result < ( ) >
490+ where T : Into < JsonValue > {
491+ match * self {
492+ JsonValue :: Object ( ref mut object) => {
493+ object. insert ( key, value. into ( ) ) ;
494+ Ok ( ( ) )
495+ } ,
496+ _ => Err ( Error :: wrong_type ( "Object" ) )
497+ }
498+ }
499+
485500 /// Works on `JsonValue::Object` - remove a key and return the value it held.
486501 /// If the key was not present, the method is called on anything but an
487502 /// object, it will return a null.
You can’t perform that action at this time.
0 commit comments