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 borrowingOption
s 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 borrowingOption
s 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)
Trait Implementations§
Source§impl<'de, V: Deserialize<'de>> Deserialize<'de> for Spanned<V>
impl<'de, V: Deserialize<'de>> Deserialize<'de> for Spanned<V>
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Source§impl<V: Ord> Ord for Spanned<V>
impl<V: Ord> Ord for Spanned<V>
Source§impl<V: PartialOrd> PartialOrd for Spanned<V>
impl<V: PartialOrd> PartialOrd for Spanned<V>
impl<V: Eq> Eq for Spanned<V>
Auto Trait Implementations§
impl<V> Freeze for Spanned<V>where
V: Freeze,
impl<V> RefUnwindSafe for Spanned<V>where
V: RefUnwindSafe,
impl<V> Send for Spanned<V>where
V: Send,
impl<V> Sync for Spanned<V>where
V: Sync,
impl<V> Unpin for Spanned<V>where
V: Unpin,
impl<V> UnwindSafe for Spanned<V>where
V: UnwindSafe,
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.