From 7d5115d6c4897e09a78a93ac4cff6ae4fa5dbeb2 Mon Sep 17 00:00:00 2001 From: Lucas Jenss Date: Wed, 18 Dec 2019 11:50:04 +0100 Subject: [PATCH] Add example for how to update value if one exists --- src/value/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/value/mod.rs b/src/value/mod.rs index eb4b900..93f9c69 100644 --- a/src/value/mod.rs +++ b/src/value/mod.rs @@ -801,6 +801,8 @@ impl Value { /// *value.pointer_mut("/x").unwrap() = 1.5.into(); /// // Check that new value was written /// assert_eq!(value.pointer("/x"), Some(&1.5.into())); + /// // Or change the value only if it exists + /// value.pointer_mut("/x").map(|v| *v = 1.5.into()); /// /// // "Steal" ownership of a value. Can replace with any valid Value. /// let old_x = value.pointer_mut("/x").map(Value::take).unwrap();