Skip to main content

DomRef

Struct DomRef 

Source
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>

Source

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());
}
Source

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> Clone for DomRef<'t, 'src>

Source§

fn clone(&self) -> DomRef<'t, 'src>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'t, 'src: 't> JsonRef<'t> for DomRef<'t, 'src>

Source§

type Item = DomRef<'t, 'src>

The concrete node type returned by get and index_at. Read more
Source§

fn is_array(self) -> bool

Returns true if this value is a JSON array.
Source§

fn is_object(self) -> bool

Returns true if this value is a JSON object.
Source§

fn as_null(self) -> Option<()>

Returns Some(()) if this value is null, otherwise None.
Source§

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>

Returns the raw number token if this value is a number, otherwise None. Read more
Source§

fn as_str(self) -> Option<&'t str>

Returns the string content if this value is a JSON string, otherwise None.
Source§

fn get(self, key: &str) -> Option<Self>

Look up an object member by key. Read more
Source§

fn index_at(self, idx: usize) -> Option<Self>

Index into an array by zero-based position. Read more
Source§

fn len(self) -> Option<usize>

Returns the number of elements (array) or key-value pairs (object). Read more
Source§

fn is_null(self) -> bool

Returns true if this value is JSON null.
Source§

fn is_bool(self) -> bool

Returns true if this value is a JSON boolean.
Source§

fn is_number(self) -> bool

Returns true if this value is a JSON number.
Source§

fn is_string(self) -> bool

Returns true if this value is a JSON string.
Source§

fn as_i64(self) -> Option<i64>

Parse the number as i64. Read more
Source§

fn as_u64(self) -> Option<u64>

Parse the number as u64. Read more
Source§

fn as_f64(self) -> Option<f64>

Parse the number as f64. Read more
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.