pub struct DomRef<'t, 'src: 't> { /* private fields */ }Expand description
A lightweight cursor into a Dom, pointing at a single entry by index.
't is the lifetime of the borrow of the tape; 'src is the lifetime of
the source JSON bytes ('src: 't). Both lifetimes collapse to the same
'a in the common case where you borrow the tape and the source in the
same scope.
Created via Dom::root. Implements crate::JsonRef.
Implementations§
Source§impl<'t, 'src: 't> DomRef<'t, 'src>
impl<'t, 'src: 't> DomRef<'t, 'src>
Sourcepub fn object_iter(self) -> Option<DomObjectIter<'t, 'src>>
pub fn object_iter(self) -> Option<DomObjectIter<'t, 'src>>
Returns an iterator over the key-value pairs if this value is a JSON
object, or None otherwise.
§Example
use asmjson::{parse_to_dom, JsonRef};
let tape = parse_to_dom(r#"{"a":1,"b":2}"#, None).unwrap();
let root = tape.root().unwrap();
for (key, val) in root.object_iter().unwrap() {
println!("{key}: {}", val.as_number_str().unwrap());
}Sourcepub fn array_iter(self) -> Option<DomArrayIter<'t, 'src>>
pub fn array_iter(self) -> Option<DomArrayIter<'t, 'src>>
Returns an iterator over the elements if this value is a JSON array,
or None otherwise.
§Example
use asmjson::{parse_to_dom, JsonRef};
let tape = parse_to_dom(r#"[1,2,3]"#, None).unwrap();
let root = tape.root().unwrap();
for elem in root.array_iter().unwrap() {
println!("{}", elem.as_number_str().unwrap());
}Trait Implementations§
Source§impl<'t, 'src: 't> JsonRef<'t> for DomRef<'t, 'src>
impl<'t, 'src: 't> JsonRef<'t> for DomRef<'t, 'src>
Source§fn as_bool(self) -> Option<bool>
fn as_bool(self) -> Option<bool>
Returns the boolean if this value is a boolean, otherwise
None.Source§fn as_number_str(self) -> Option<&'t str>
fn as_number_str(self) -> Option<&'t str>
Returns the raw number token if this value is a number, otherwise
None. Read moreSource§fn as_str(self) -> Option<&'t str>
fn as_str(self) -> Option<&'t str>
Returns the string content if this value is a JSON string, otherwise
None.Source§fn index_at(self, idx: usize) -> Option<Self>
fn index_at(self, idx: usize) -> Option<Self>
Index into an array by zero-based position. Read more
impl<'t, 'src: 't> Copy for DomRef<'t, 'src>
Auto Trait Implementations§
impl<'t, 'src> Freeze for DomRef<'t, 'src>
impl<'t, 'src> RefUnwindSafe for DomRef<'t, 'src>
impl<'t, 'src> Send for DomRef<'t, 'src>
impl<'t, 'src> Sync for DomRef<'t, 'src>
impl<'t, 'src> Unpin for DomRef<'t, 'src>
impl<'t, 'src> UnsafeUnpin for DomRef<'t, 'src>
impl<'t, 'src> UnwindSafe for DomRef<'t, 'src>
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
Mutably borrows from an owned value. Read more