pub struct Document<'buf> { /* private fields */ }Expand description
The output of parse_object: the element tree with path resolution embedded in each
element.
Implementations§
Source§impl<'buf> Document<'buf>
impl<'buf> Document<'buf>
Sourcepub fn source(&self) -> &'buf str
pub fn source(&self) -> &'buf str
Returns the source JSON string this document was parsed from.
Sourcepub fn element(&self, id: ElemId) -> Option<&Element<'buf>>
pub fn element(&self, id: ElemId) -> Option<&Element<'buf>>
Returns the element with id, or None if this document has no such element.
Walks the parent chain up from id and then descends back down the tree, so the
cost is O(depth) plus a scan of each ancestor’s children. Meant for looking up
the occasional edit site, not for bulk traversal.
NOTE: an ElemId produced by a different parse of the same source &str
cannot be told apart from one of this document’s own ids.
Sourcepub fn removal_spans(
&self,
ids: &BTreeSet<ElemId>,
) -> Result<Vec<Span>, RemovalError>
pub fn removal_spans( &self, ids: &BTreeSet<ElemId>, ) -> Result<Vec<Span>, RemovalError>
Resolves the source spans to erase in order to remove every element in ids.
The returned spans are sorted by start offset and never overlap, so erasing them
from Document::source leaves JSON that still parses.
Siblings are resolved as a group, because which span removes a child depends on which of its siblings survive:
| Case | Span erased |
|---|---|
| Run of children followed by a surviving sibling | the run’s first key or value, up to the start of that sibling |
| Run of children reaching the closing delimiter | the end of the last surviving sibling’s value, up to the end of the run |
| Every child of an object or array | everything between the {} or [] delimiters |
A run that reaches the closing delimiter carries no trailing comma of its own, so it has to swallow the comma of the sibling before it. Resolving each id on its own and merging the spans afterwards gets that case wrong: it leaves the earlier sibling’s comma dangling.
An id nested inside another id in the same set needs nothing beyond being dropped, since the ancestor’s span already covers it.
Trait Implementations§
Auto Trait Implementations§
impl<'buf> !Send for Document<'buf>
impl<'buf> !Sync for Document<'buf>
impl<'buf> Freeze for Document<'buf>
impl<'buf> RefUnwindSafe for Document<'buf>
impl<'buf> Unpin for Document<'buf>
impl<'buf> UnsafeUnpin for Document<'buf>
impl<'buf> UnwindSafe for Document<'buf>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoCaveat for T
impl<T> IntoCaveat for T
Source§fn into_caveat<W>(self, warnings: Set<W>) -> Caveat<T, W>where
W: Warning,
fn into_caveat<W>(self, warnings: Set<W>) -> Caveat<T, W>where
W: Warning,
Caveat<T> by supplying a list of Warnings.Source§fn into_infallible_caveat(self) -> Caveat<Self, Infallible>
fn into_infallible_caveat(self) -> Caveat<Self, Infallible>
FromSchema is infallible a Caveat can be created using this method.