pub fn parse_path(path: &str) -> Vec<PathSegment>Expand description
Parse a path string into components.
Supports multiple syntaxes:
- Dot notation:
"server.host"→[Key("server"), Key("host")] - Array indices with brackets:
"items[0].name"→[Key("items"), Index(0), Key("name")] - Array indices with dots:
"items.0.name"→[Key("items"), Index(0), Key("name")] - Escaped dots:
"key\\.with\\.dots"→[Key("key.with.dots")]
§Examples
use yaml_edit::path::{parse_path, PathSegment};
let segments = parse_path("server.host");
assert_eq!(segments, vec![
PathSegment::Key("server".to_string()),
PathSegment::Key("host".to_string())
]);
let segments = parse_path("items[0].name");
assert_eq!(segments, vec![
PathSegment::Key("items".to_string()),
PathSegment::Index(0),
PathSegment::Key("name".to_string())
]);
let segments = parse_path("items.0");
assert_eq!(segments, vec![
PathSegment::Key("items".to_string()),
PathSegment::Index(0)
]);