IndexOrKey

Trait IndexOrKey 

Source
pub trait IndexOrKey {
    // Required methods
    fn get(self, value: &Value) -> Option<&Value>;
    fn get_mut(self, value: &mut Value) -> Option<&mut Value>;
    fn get_or_insert(self, value: &mut Value) -> &mut Value;
}
Expand description

Allows for indexing into a Value by String or usize

Required Methods§

Source

fn get(self, value: &Value) -> Option<&Value>

Get an immutable reference to a Value.

Source

fn get_mut(self, value: &mut Value) -> Option<&mut Value>

Get a mutable reference to a Value.

Source

fn get_or_insert(self, value: &mut Value) -> &mut Value

Get a mutable reference or insert Value::Null and return a mutable reference to that.

Implementations on Foreign Types§

Source§

impl IndexOrKey for &str

Source§

fn get(self, value: &Value) -> Option<&Value>

Get an immutable reference to a Value in a Value::Object.

Source§

fn get_mut(self, value: &mut Value) -> Option<&mut Value>

Get a mutable reference to a Value in a Value::Object.

Source§

fn get_or_insert(self, value: &mut Value) -> &mut Value

Get a mutable reference to a Value in a Value::Object if it exists, otherwise insert Value::Null and return a mutable reference to that.

Source§

impl IndexOrKey for usize

Source§

fn get(self, value: &Value) -> Option<&Value>

Get an immutable reference to a Value in a Value::Array.

Source§

fn get_mut(self, value: &mut Value) -> Option<&mut Value>

Get an immutable reference to a Value in a Value::Array.

Source§

fn get_or_insert(self, _value: &mut Value) -> &mut Value

Get a mutable refence to a Value in a Value::Array. This function will panic if the Value is not an array.

Source§

impl IndexOrKey for String

Source§

fn get(self, value: &Value) -> Option<&Value>

Get an immutable reference to a Value in a Value::Object.

Source§

fn get_mut(self, value: &mut Value) -> Option<&mut Value>

Get a mutable reference to a Value in a Value::Object.

Source§

fn get_or_insert(self, value: &mut Value) -> &mut Value

Get a mutable reference to a Value in a Value::Object if it exists, otherwise insert Value::Null and return a mutable reference to that.

Implementors§