Trait Index

Source
pub trait Index: Sealed { }
Expand description

A type that can be used to index into a Value.

The get and get_mut methods of Value accept any type that implements Index, as does the square-bracket indexing operator. This trait is implemented for strings which are used as the index into a map, and for usize which is used as the index into an array.

This trait is sealed and cannot be implemented for types outside of tower_sesh.

§Examples

let value = Value::from_iter([("inner", [1, 2, 3])]);

// Data is a map so it can be indexed with a string.
let inner = &value["inner"];

// Inner is an array so it can be indexed with an integer.
let first = &inner[0];

assert_eq!(first, 1);

Implementations on Foreign Types§

Source§

impl Index for str

Source§

impl Index for usize

Source§

impl Index for String

Source§

impl<T> Index for &T
where T: ?Sized + Index,

Implementors§