Trait polyvalue::operations::IndexingOperationExt
source · 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§
sourcefn get_index(&self, index: &Value) -> Result<Value, Error>
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));