From 08ec72f568aae58fe0837b8df499d419024a624b Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sun, 19 Jan 2020 00:44:09 +0800 Subject: [PATCH] add mut --- serde-json-test/src/main.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/serde-json-test/src/main.rs b/serde-json-test/src/main.rs index a484804..c350f64 100644 --- a/serde-json-test/src/main.rs +++ b/serde-json-test/src/main.rs @@ -39,7 +39,7 @@ fn main() -> Result<()> { let v: Value = serde_json::from_str(data)?; println!("{}", v); - let john = json!({ + let mut john = json!({ "name": "John Doe", "age": 43, "phones": [ @@ -47,6 +47,12 @@ fn main() -> Result<()> { "+44 2345678" ] }); + println!("{}", &john); + + if let Option::Some(ref mut m) = john.as_object_mut() { + m.insert("test".into(), Value::Bool(true)); + m.insert("test2".into(), Value::String("hello world".into())); + } println!("{}", john); Ok(())