pub fn parse_path(spec: &str) -> Result<Vec<Seg>, String>Expand description
Parse a dotted/bracketed path; a leading . is optional. Keys are
dot-separated; [N] selects an array index and [key=value] selects the
object in an array whose key equals value.
ยงExamples
use coding_tools::patch::{parse_path, Seg};
assert_eq!(
parse_path("a[2].c").unwrap(),
vec![Seg::Key("a".into()), Seg::Index(2), Seg::Key("c".into())]
);
assert_eq!(
parse_path(".servers[name=web].port").unwrap(),
vec![
Seg::Key("servers".into()),
Seg::Select { key: "name".into(), value: "web".into() },
Seg::Key("port".into()),
]
);
assert!(parse_path("").is_err());
assert!(parse_path("a[x]").is_err()); // not an index and not key=value