Skip to main content

DomEntry

Struct DomEntry 

Source
pub struct DomEntry<'a> { /* private fields */ }
Expand description

A single token in a Dom.

The representation is a fixed-size 16-byte struct:

wordbitsmeaning
0 (offset 0)63–60DomEntryKind discriminant
0 (offset 0)59–0string/key length or object/array end-index
1 (offset 8)63–0pointer to string bytes (null for non-string kinds)

For EscapedString / EscapedKey the pointer is the data pointer of a Box<str> whose ownership is transferred into (and out of) this entry. DomEntry implements Drop to free that allocation.

For Bool the low bit of the payload encodes the value (0 = false, 1 = true). For Null, EndObject, EndArray both payload and pointer are zero.

Implementations§

Source§

impl<'a> DomEntry<'a>

Source

pub fn kind(&self) -> DomEntryKind

The discriminant.

Source

pub fn null_entry() -> Self

Source

pub fn bool_entry(v: bool) -> Self

Source

pub fn number_entry(s: &'a str) -> Self

Source

pub fn string_entry(s: &'a str) -> Self

Source

pub fn escaped_string_entry(s: Box<str>) -> Self

Source

pub fn key_entry(s: &'a str) -> Self

Source

pub fn escaped_key_entry(s: Box<str>) -> Self

Source

pub fn start_object_entry(end_idx: usize) -> Self

payload will be backfilled with the end-index later.

Source

pub fn end_object_entry() -> Self

Source

pub fn start_array_entry(end_idx: usize) -> Self

payload will be backfilled with the end-index later.

Source

pub fn end_array_entry() -> Self

Source

pub fn as_start_object(&self) -> Option<usize>

Returns Some(end_index) if this is StartObject, else None.

Source

pub fn as_start_array(&self) -> Option<usize>

Returns Some(end_index) if this is StartArray, else None.

Source

pub fn as_bool(&self) -> Option<bool>

Returns Some(b) if this is Bool, else None.

Source

pub fn as_number(&self) -> Option<&'a str>

Returns the number text if this is Number, else None.

Source

pub fn as_string(&self) -> Option<&str>

Returns the string text if this is String or EscapedString, else None.

Source

pub fn as_key(&self) -> Option<&str>

Returns the key text if this is Key or EscapedKey, else None.

Source§

impl<'a> DomEntry<'a>

Convenience constructors using the old enum-variant names so existing test/user code keeps a familiar style.

Source

pub const Null: DomEntry<'static>

Alias: DomEntry::NullDomEntry::null_entry().

Source

pub const EndObject: DomEntry<'static>

Alias: DomEntry::EndObjectDomEntry::end_object_entry().

Source

pub const EndArray: DomEntry<'static>

Alias: DomEntry::EndArrayDomEntry::end_array_entry().

Source

pub fn Bool(v: bool) -> Self

Construct a Bool entry. Replaces DomEntry::Bool(v).

Source

pub fn Number(s: &'a str) -> Self

Construct a Number entry. Replaces DomEntry::Number(s).

Source

pub fn String(s: &'a str) -> Self

Construct a String entry. Replaces DomEntry::String(s).

Source

pub fn EscapedString(s: Box<str>) -> Self

Construct an EscapedString entry. Replaces DomEntry::EscapedString(b).

Source

pub fn Key(s: &'a str) -> Self

Construct a Key entry. Replaces DomEntry::Key(s).

Source

pub fn EscapedKey(s: Box<str>) -> Self

Construct an EscapedKey entry. Replaces DomEntry::EscapedKey(b).

Source

pub fn StartObject(end_idx: usize) -> Self

Construct a StartObject entry. Replaces DomEntry::StartObject(n).

Source

pub fn StartArray(end_idx: usize) -> Self

Construct a StartArray entry. Replaces DomEntry::StartArray(n).

Trait Implementations§

Source§

impl<'a> Clone for DomEntry<'a>

Source§

fn clone(&self) -> Self

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<'a> Debug for DomEntry<'a>

Custom Debug that renders the same variant names as the old enum.

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Drop for DomEntry<'a>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<'a> PartialEq for DomEntry<'a>

Equality. For EscapedString/EscapedKey we compare the string content.

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> Send for DomEntry<'a>

Source§

impl<'a> Sync for DomEntry<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for DomEntry<'a>

§

impl<'a> RefUnwindSafe for DomEntry<'a>

§

impl<'a> Unpin for DomEntry<'a>

§

impl<'a> UnsafeUnpin for DomEntry<'a>

§

impl<'a> UnwindSafe for DomEntry<'a>

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.