tremor_value::prelude

Trait ValueAsMutContainer

source
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§

source

type Array

The type for Arrays

source

type Object

The type for Objects

Required Methods§

source

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

source

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

source§

type Array = Vec<Value>

source§

type Object = SizedHashMap<String, Value, NotSoRandomState>

source§

fn as_array_mut(&mut self) -> Option<&mut Vec<Value>>

source§

fn as_object_mut( &mut self, ) -> Option<&mut SizedHashMap<String, Value, NotSoRandomState>>

source§

impl<'value> ValueAsMutContainer for Value<'value>

source§

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}));
source§

type Array = Vec<Value<'value>>

source§

type Object = SizedHashMap<Cow<'value, str>, Value<'value>, NotSoRandomState>

source§

fn as_array_mut(&mut self) -> Option<&mut Vec<Value<'value>>>

Implementors§

source§

impl<'value> ValueAsMutContainer for tremor_value::value::Value<'value>

source§

type Array = Vec<Value<'value>>

source§

type Object = SizedHashMap<Cow<'value, str, Wide>, Value<'value>, NotSoRandomState>