pub struct Spanned<V> { /* private fields */ }Expand description
A value with start/end position information. Can wrap arbitrary Deserializeable JSON values, not just basic JSON types.
Implementations§
Source§impl<V> Spanned<V>
impl<V> Spanned<V>
Sourcepub fn start(&self) -> usize
pub fn start(&self) -> usize
Get the starting byte offset (inclusive) of this value.
Likely 0 unless loaded through crate::from_*.
Sourcepub fn end(&self) -> usize
pub fn end(&self) -> usize
Get the ending byte offset (non-inclusive) of this value.
Likely 0 unless loaded through crate::from_*.
Sourcepub fn span(&self) -> (usize, usize)
pub fn span(&self) -> (usize, usize)
Get the start .. end byte offset of this value as a (start, end) tuple.
Likely (0, 0) unless loaded through crate::from_*.
Sourcepub fn range(&self) -> Range<usize>
pub fn range(&self) -> Range<usize>
Get the start .. end byte offset of this value as a start .. end Range.
Likely 0 .. 0 unless loaded through crate::from_*.
Sourcepub fn into_inner(self) -> V
pub fn into_inner(self) -> V
Get the interior value of the spanned region as an owned value.
Source§impl Spanned<Value>
Various conversion methods:
impl Spanned<Value>
Various conversion methods:
as_span_[type]()returns borrowingOptions of some sort.into_span_[type]()returnsOk(type)orErr(original).
See also on super::Value as provided by Deref implementation:
is_[type]()returns bools with obvious meanings.as_[type]()for borrowingOptions without span info.into_[type]()forOk(type)without span info, orErr(original).
Sourcepub fn as_span_null(&self) -> Option<Null>
pub fn as_span_null(&self) -> Option<Null>
Some(span + ()) if self is null`
Sourcepub fn as_span_bool(&self) -> Option<Bool>
pub fn as_span_bool(&self) -> Option<Bool>
Some(span + inner) if self is true or false
Sourcepub fn as_span_number(&self) -> Option<Num<'_>>
pub fn as_span_number(&self) -> Option<Num<'_>>
Some(span + &inner) if self is a number like 123
Sourcepub fn as_span_string(&self) -> Option<Str<'_>>
pub fn as_span_string(&self) -> Option<Str<'_>>
Some(span + &inner) if self is a string like "asdf"
Sourcepub fn as_span_array(&self) -> Option<Span<'_>>
pub fn as_span_array(&self) -> Option<Span<'_>>
Some(span + &inner) if self is an array like [1, 2, 3]
Sourcepub fn as_span_object(&self) -> Option<Obj<'_>>
pub fn as_span_object(&self) -> Option<Obj<'_>>
Some(span + &inner) if self is an object like {"a": 1, "b": 2}
Sourcepub fn into_span_null(self) -> Result<Null, Self>
pub fn into_span_null(self) -> Result<Null, Self>
Ok(span + ()) if self is null, otherwise Err(self)
Sourcepub fn into_span_bool(self) -> Result<Bool, Self>
pub fn into_span_bool(self) -> Result<Bool, Self>
Ok(span + inner) if self is true or false, otherwise Err(self)
Sourcepub fn into_span_number(self) -> Result<Number, Self>
pub fn into_span_number(self) -> Result<Number, Self>
Ok(span + inner) if self is a number like 123, otherwise Err(self)
Sourcepub fn into_span_string(self) -> Result<String, Self>
pub fn into_span_string(self) -> Result<String, Self>
Ok(span + inner) if self is a string like "asdf", otherwise Err(self)
Sourcepub fn into_span_array(self) -> Result<Array, Self>
pub fn into_span_array(self) -> Result<Array, Self>
Ok(span + inner) if self is an array like [1, 2, 3], otherwise Err(self)
Sourcepub fn into_span_object(self) -> Result<Object, Self>
pub fn into_span_object(self) -> Result<Object, Self>
Ok(span + inner) if self is an object like {"a": 1, "b": 2}, otherwise Err(self)