Function cbor_data::try_index_str

source ·
pub fn try_index_str(s: &str) -> Option<IndexStr<'_>>
Expand description

Generate an iterator of PathElement from a string

A path element is either

  • a string starting with any other character than dot or opening bracket and delimited by the next dot or opening bracket
  • a number enclosed in brackets

None is returned in case an opening bracket is not matched with a closing one or the characters between brackets are not a valid representation of u64.

§Examples:

use cbor_data::{Cbor, index_str, ItemKind};

let cbor = Cbor::checked(b"eActyx").unwrap();

// dict key `x`, array index 12, dict key `y`
assert_eq!(cbor.index(index_str("x[12].y")), None);
// empty string means the outermost item
assert!(matches!(cbor.index(index_str("")).unwrap().kind(), ItemKind::Str(s) if s == "Actyx"));