pub fn apply_indexes(value: Value, indexes: &[IndexExpr]) -> Result<Value>Expand description
Applies a sequence of index expressions to a value and returns the result.
Supports indexing into Value::List and Value::Map with IndexExpr::Int
and IndexExpr::String respectively, and into Value::String with
IndexExpr::Int (character index). Any other combination returns an error.
Typically called inside a crate::PathAccessor implementation to apply per-field
keys: apply_indexes(base_value, &field.keys).
§Errors
Returns an error if an index is out of bounds, a map key is missing, or the value type does not support the given index type.
§Example
ⓘ
use ottl::helpers::apply_indexes;
use ottl::{Value, IndexExpr};
let list = Value::List(vec![Value::Int(1), Value::Int(2)]);
let keys = [IndexExpr::Int(0)];
let v = apply_indexes(list, &keys)?;
assert!(matches!(v, Value::Int(1)));