pub trait IndexingOperationExt {
    // Required methods
    fn get_index(&self, index: &Value) -> Result<Value, Error>;
    fn get_indices(&self, index: &Value) -> Result<Value, Error>;
}
Expand description

Indexing operation trait

Required Methods§

source

fn get_index(&self, index: &Value) -> Result<Value, Error>

Get a value from an index Returns a value, or an Error::Index if the index is not found

§Examples
use polyvalue::{Value};
use polyvalue::types::{Object};
use polyvalue::operations::{IndexingOperationExt};

let a = Value::from(vec![Value::from(1), Value::from(2), Value::from(3)]);
let index = Value::from(1);
let result = a.get_index(&index).unwrap();
assert_eq!(result, Value::from(2));

let b = Object::try_from(vec![("a", 1), ("b", 2)]).unwrap();
let index = Value::from("b");
let result = b.get_index(&index).unwrap();
assert_eq!(result, Value::from(2));
source

fn get_indices(&self, index: &Value) -> Result<Value, Error>

Get values from one or more indices Returns a vector of values, or an Error::Index if any of the indices are not found

Acts as a convenience wrapper around get_index where array values are treated as a set of indices

Implementors§