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>
Sourcepub fn span(&self) -> Span
pub fn span(&self) -> Span
Returns the span covering this element’s value alone, without any trailing comma.
See Element::full_span for the span that reaches the next sibling.
Sourcepub fn full_span(&self) -> Span
pub fn full_span(&self) -> Span
Returns the span covering the value plus any trailing comma and the whitespace after it, so the span ends where the next sibling begins.
When there is no trailing comma (the root element, or the last child of its
parent), full_span() == span().
Use Element::span to replace a value. Removal is not simply a matter of
erasing full_span: which span removes a child depends on which of its siblings
survive, and erasing the full_span of a last child leaves a dangling comma on
the sibling before it. Use Document::removal_spans, which resolves a whole set
of removals against the surviving siblings.
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.
Sourcepub fn as_array(&self) -> Option<&[Element<'buf>]>
pub fn as_array(&self) -> Option<&[Element<'buf>]>
Returns the items if this element is a JSON array, None otherwise.
Sourcepub fn as_number_str(&self) -> Option<&str>
pub fn as_number_str(&self) -> Option<&str>
Returns the number as it was written in the source if this element is a JSON number,
None otherwise. The text is not parsed, so it keeps the precision the document had.
Trait Implementations§
impl Eq for Element<'_>
Auto Trait Implementations§
impl<'buf> !Send for Element<'buf>
impl<'buf> !Sync for Element<'buf>
impl<'buf> Freeze for Element<'buf>
impl<'buf> RefUnwindSafe for Element<'buf>
impl<'buf> Unpin for Element<'buf>
impl<'buf> UnsafeUnpin for Element<'buf>
impl<'buf> UnwindSafe for Element<'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.