Skip to main content

JsonText

Enum JsonText 

Source
pub enum JsonText {
    Null,
    Bool(bool),
    Number(String),
    String(JsonString),
    Array(Vec<JsonText>),
    Object(Vec<(JsonString, JsonText)>),
    Shared(Arc<JsonText>),
    Link(Weak<JsonText>),
}
Expand description

A JSON document read without replacing any text.

JsonText::Shared and JsonText::Link hold what JSON text cannot write: a value placed in several parents, and a link back to a shared value that contains it, which makes a value that contains itself. Neither is a node of its own: a walk counts each visit of the value it denotes, as the TypeScript and Go runtimes do, so the node and nesting limits bound every walk. A link must refer to a value that its owner holds; the parser never produces either variant.

Variants§

§

Null

null.

§

Bool(bool)

true or false.

§

Number(String)

A number, kept as written.

§

String(JsonString)

A string.

§

Array(Vec<JsonText>)

An array.

§

Object(Vec<(JsonString, JsonText)>)

An object with unique member names.

§

Shared(Arc<JsonText>)

A value shared by several parents.

A link to a shared value, which makes a cycle when the link is inside that value.

Implementations§

Source§

impl JsonText

Source

pub fn parse(text: &str) -> Result<JsonText, JsonTextError>

Read one JSON document with the grammar and nesting limit serde_json applies, keeping every string as written.

Source

pub fn get(&self, name: &str) -> Option<&JsonText>

The member name of an object. A shared object is read through its target; a link is not.

Source

pub fn item(&self, index: usize) -> Option<&JsonText>

The item at index of an array. A shared array is read through its target; a link is not.

Source

pub fn to_value(&self) -> Option<Value>

The value as Value, or None when it holds invalid text, a number serde_json does not accept, or a value beyond its limits.

Source

pub fn shape(&self) -> Value

The document’s shape for request checks that read only kinds and valid names: invalid text becomes an empty string, an invalid member name a name no valid request member uses, and a number serde_json does not accept null. A value beyond its limits has no shape and is null. The shape is never an operation input; the text checks run before any part of it reaches an operation.

Source

pub fn has_invalid_text(&self) -> bool

Whether the first failure of the value is invalid text (see JsonText::invalid_path).

Source

pub fn invalid_path(&self) -> Option<Vec<String>>

The path of the first failure when it is invalid text: the path of a string, or of the object whose member name is invalid. Members are visited in code point order of their names after every member name is checked, and array items in index order.

Source

pub fn has_limit_violation(&self) -> bool

Whether this value holds a limit violation (too many nodes or too deep nesting).

Trait Implementations§

Source§

impl Clone for JsonText

Source§

fn clone(&self) -> JsonText

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for JsonText

Source§

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

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

impl PartialEq for JsonText

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more

Auto Trait Implementations§

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.