pub enum ValuePointerRef<'a> {
Origin,
Key {
key: &'a str,
prev: &'a ValuePointerRef<'a>,
},
Index {
index: usize,
prev: &'a ValuePointerRef<'a>,
},
}
Expand description
A location within a Value
.
Conceptually, it is a list of choices that one has to make to go to a certain place within the value. In practice, it is used to locate the origin of a deserialization error.
§Example
use deserr::ValuePointerRef;
let pointer = ValuePointerRef::Origin;
let pointer = pointer.push_key("a");
let pointer = pointer.push_index(2);
// now `pointer` points to "a".2
A ValuePointerRef
is an immutable data structure, so it is cheap to extend and to copy.
However, if you want to store it inside an owned type, you may want to convert it to a
ValuePointer
instead using self.to_owned()
.
Variants§
Implementations§
Source§impl<'a> ValuePointerRef<'a>
impl<'a> ValuePointerRef<'a>
Sourcepub fn push_key(&'a self, key: &'a str) -> Self
pub fn push_key(&'a self, key: &'a str) -> Self
Extend self
such that it points to the next subvalue at the given key
.
Sourcepub fn push_index(&'a self, index: usize) -> Self
pub fn push_index(&'a self, index: usize) -> Self
Extend self
such that it points to the next subvalue at the given index.
Sourcepub fn last_field(&self) -> Option<&str>
pub fn last_field(&self) -> Option<&str>
Return the last field encountered if there is one.
Sourcepub fn first_field(&self) -> Option<&str>
pub fn first_field(&self) -> Option<&str>
Return the first field encountered if there is one. Eg; “toto.tata[42].lol” -> “toto” “toto” -> “toto” “[1][2][3]” -> None “” -> None
Sourcepub fn to_owned(&self) -> ValuePointer
pub fn to_owned(&self) -> ValuePointer
Convert self
to its owned version
Trait Implementations§
Source§impl<'a> Clone for ValuePointerRef<'a>
impl<'a> Clone for ValuePointerRef<'a>
Source§fn clone(&self) -> ValuePointerRef<'a>
fn clone(&self) -> ValuePointerRef<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more