pub trait ValueAsMutContainer {
type Array;
type Object;
// Required methods
fn as_array_mut(&mut self) -> Option<&mut Self::Array>;
fn as_object_mut(&mut self) -> Option<&mut Self::Object>;
}
Expand description
Mutatability for container values
Required Associated Types§
Required Methods§
sourcefn as_array_mut(&mut self) -> Option<&mut Self::Array>
fn as_array_mut(&mut self) -> Option<&mut Self::Array>
Tries to represent the value as an array and returns a mutable reference to it
sourcefn as_object_mut(&mut self) -> Option<&mut Self::Object>
fn as_object_mut(&mut self) -> Option<&mut Self::Object>
Tries to represent the value as an object and returns a mutable reference to it
Implementations on Foreign Types§
source§impl ValueAsMutContainer for Value
impl ValueAsMutContainer for Value
source§impl<'value> ValueAsMutContainer for Value<'value>
impl<'value> ValueAsMutContainer for Value<'value>
source§fn as_object_mut(
&mut self,
) -> Option<&mut SizedHashMap<Cow<'value, str>, Value<'value>, NotSoRandomState>>
fn as_object_mut( &mut self, ) -> Option<&mut SizedHashMap<Cow<'value, str>, Value<'value>, NotSoRandomState>>
Get mutable access to a map.
use simd_json::*;
use value_trait::prelude::*;
let mut object: BorrowedValue = json!({
"answer": 23,
"key": 7
}).into();
assert_eq!(object["answer"], 23);
if let Some(inner) = object.as_object_mut() {
inner.insert("value".into(), BorrowedValue::from(json!({"nested": 42})));
}
assert_eq!(object["value"], json!({"nested": 42}));