pub struct Element<'buf> { /* private fields */ }Expand description
A JSON Element with identity, source span, and value.
Each element carries a shared reference to the document it was parsed from,
so Element::path() can resolve its path.
Implementations§
Source§impl<'buf> Element<'buf>
impl<'buf> Element<'buf>
pub fn id(&self) -> ElemId
pub fn span(&self) -> Span
Sourcepub fn full_span(&self) -> Span
pub fn full_span(&self) -> Span
Returns the span covering the value plus any trailing comma and whitespace.
Choose the removal span based on the element’s position in its parent:
| Case | Span to erase |
|---|---|
| Replace value | Element::span |
| Remove non-last item | element.full_span() |
| Remove last item (siblings exist) | siblings[i-1].span().end .. element.span().end |
| Remove only item | element.span() |
When there is no trailing comma (root element or last sibling),
full_span() == span(). Erasing full_span of a last item leaves a
dangling comma on the previous sibling; use the predecessor’s span().end
as the start of the removal range instead.
pub fn value(&self) -> &Value<'buf>
Sourcepub fn path(&self) -> Path
pub fn path(&self) -> Path
Returns the RFC 9535 path to this element.
NOTE: The Path is constructed anew every time this functions is called.
Sourcepub fn source_json_value(&self) -> &'buf str
pub fn source_json_value(&self) -> &'buf str
Returns the slice of the source JSON that this element spans.
Sourcepub fn source(&self) -> &'buf str
pub fn source(&self) -> &'buf str
The full source string; all element spans are relative to this.
Sourcepub fn to_raw_str(&self) -> Option<RawStr<'buf>>
pub fn to_raw_str(&self) -> Option<RawStr<'buf>>
Return Some(&str) if the Value is a String.
Sourcepub fn as_object_fields(&self) -> Option<&[Field<'buf>]>
pub fn as_object_fields(&self) -> Option<&[Field<'buf>]>
Return Some(&[Field]) if the Value is a Object.