File tree 1 file changed +15
-0
lines changed
1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -482,6 +482,21 @@ impl JsonValue {
482
482
}
483
483
}
484
484
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
+
485
500
/// Works on `JsonValue::Object` - remove a key and return the value it held.
486
501
/// If the key was not present, the method is called on anything but an
487
502
/// object, it will return a null.
You can’t perform that action at this time.
0 commit comments