pub struct Path { /* private fields */ }Expand description
A parsed, validated context path — the canonical IR for the flow.ir
$.a.b / ctx.a.b / RFC 9535-style bracket path syntax. The full
syntax and rejection rules are documented on the module-level docs and
on Path::read / Path::write and the FromStr implementation
below.
Illegal path syntax cannot be represented by this type: the only way to
construct a Path is FromStr::from_str (equivalently str::parse)
or Deserialize, both of which reject malformed input up front. Once
you hold a Path, Path::read / Path::write never re-derive or
re-validate the segment list.
Implementations§
Source§impl Path
impl Path
Sourcepub fn read<'a>(&self, ctx: &'a Value) -> Result<&'a Value, EvalError>
pub fn read<'a>(&self, ctx: &'a Value) -> Result<&'a Value, EvalError>
Read the value this path resolves to inside ctx.
The root path ($ / ctx with no segments) resolves to ctx
itself. A missing key along the way raises
EvalError::PathNotFound — malformed syntax is rejected earlier,
at parse time, so read can never raise EvalError::InvalidPath.
Sourcepub fn write(&self, ctx: &mut Value, value: Value) -> Result<(), EvalError>
pub fn write(&self, ctx: &mut Value, value: Value) -> Result<(), EvalError>
Write value at the location this path resolves to inside ctx,
mutating ctx in place.
The root path ($ / ctx with no segments) replaces ctx
wholesale. Missing intermediate objects along the way are created
automatically (a null — or altogether absent — intermediate
promotes to an empty object, same as before this type existed). If
an intermediate segment already holds a concrete non-object value
(a string, number, bool, or array), the write is rejected with
EvalError::TypeError instead of silently clobbering it; ctx is
left byte-for-byte unmodified in that case (a rejected write never
partially applies, because every intermediate object promotion this
method performs only ever touches a freshly-created — previously
null/absent — subtree, which by construction cannot itself contain
a pre-existing conflicting value further down).
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Path
impl<'de> Deserialize<'de> for Path
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl Display for Path
impl Display for Path
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Canonical string form: the original root token ($ or ctx) +
.key for each identifier-safe segment, ["key"] bracket form
otherwise. Path::from_str(path.to_string()) always re-parses to an
equal Path (round-trip law, including root-token preservation) —
the canonical form may normalize each segment’s representation
(e.g. a segment reachable only via dot form on the way in is still
rendered via dot form; a segment that required bracket form on the
way in is rendered via bracket form) without changing the parsed
segment list.