Trait lexpr::Index

source ·
pub trait Index: Sealed { }
Expand description

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

The get method of Value accept any type that implements Index, as does the square-bracket indexing operator. This trait is implemented for strings and Value, both of which can be used to index into association lists, and for usize which is used to index into to lists by element index.

Note that improper lists are only indexable by usize, not by strings.

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

Examples

let data = sexp!(((foo 42) (bar . (1 2 3))));

// Data is an association list so it can be indexed with a string.
let bar = &data["bar"];

// Bar is a list so it can be indexed with an integer.
let second = &bar[1];

assert_eq!(second, 2);

Implementations on Foreign Types§

source§

impl Index for str

source§

impl Index for usize

source§

impl<'a, T> Index for &'a Twhere T: Index + ?Sized,

source§

impl Index for String

Implementors§