pub struct DomEntry<'a> { /* private fields */ }Expand description
A single token in a Dom.
The representation is a fixed-size 16-byte struct:
| word | bits | meaning |
|---|---|---|
| 0 (offset 0) | 63–60 | DomEntryKind discriminant |
| 0 (offset 0) | 59–0 | string/key length or object/array end-index |
| 1 (offset 8) | 63–0 | pointer 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>
impl<'a> DomEntry<'a>
Sourcepub fn kind(&self) -> DomEntryKind
pub fn kind(&self) -> DomEntryKind
The discriminant.
pub fn null_entry() -> Self
pub fn bool_entry(v: bool) -> Self
pub fn number_entry(s: &'a str) -> Self
pub fn string_entry(s: &'a str) -> Self
pub fn escaped_string_entry(s: Box<str>) -> Self
pub fn key_entry(s: &'a str) -> Self
pub fn escaped_key_entry(s: Box<str>) -> Self
Sourcepub fn start_object_entry(end_idx: usize) -> Self
pub fn start_object_entry(end_idx: usize) -> Self
payload will be backfilled with the end-index later.
pub fn end_object_entry() -> Self
Sourcepub fn start_array_entry(end_idx: usize) -> Self
pub fn start_array_entry(end_idx: usize) -> Self
payload will be backfilled with the end-index later.
pub fn end_array_entry() -> Self
Sourcepub fn as_start_object(&self) -> Option<usize>
pub fn as_start_object(&self) -> Option<usize>
Returns Some(end_index) if this is StartObject, else None.
Sourcepub fn as_start_array(&self) -> Option<usize>
pub fn as_start_array(&self) -> Option<usize>
Returns Some(end_index) if this is StartArray, else None.
Sourcepub fn as_number(&self) -> Option<&'a str>
pub fn as_number(&self) -> Option<&'a str>
Returns the number text if this is Number, else None.
Source§impl<'a> DomEntry<'a>
Convenience constructors using the old enum-variant names so existing
test/user code keeps a familiar style.
impl<'a> DomEntry<'a>
Convenience constructors using the old enum-variant names so existing test/user code keeps a familiar style.
Sourcepub const EndObject: DomEntry<'static>
pub const EndObject: DomEntry<'static>
Alias: DomEntry::EndObject → DomEntry::end_object_entry().
Sourcepub fn EscapedString(s: Box<str>) -> Self
pub fn EscapedString(s: Box<str>) -> Self
Construct an EscapedString entry. Replaces DomEntry::EscapedString(b).
Sourcepub fn EscapedKey(s: Box<str>) -> Self
pub fn EscapedKey(s: Box<str>) -> Self
Construct an EscapedKey entry. Replaces DomEntry::EscapedKey(b).
Sourcepub fn StartObject(end_idx: usize) -> Self
pub fn StartObject(end_idx: usize) -> Self
Construct a StartObject entry. Replaces DomEntry::StartObject(n).
Sourcepub fn StartArray(end_idx: usize) -> Self
pub fn StartArray(end_idx: usize) -> Self
Construct a StartArray entry. Replaces DomEntry::StartArray(n).
Trait Implementations§
Source§impl<'a> Debug for DomEntry<'a>
Custom Debug that renders the same variant names as the old enum.
impl<'a> Debug for DomEntry<'a>
Custom Debug that renders the same variant names as the old enum.
Source§impl<'a> PartialEq for DomEntry<'a>
Equality. For EscapedString/EscapedKey we compare the string content.
impl<'a> PartialEq for DomEntry<'a>
Equality. For EscapedString/EscapedKey we compare the string content.