Struct sonic_rs::Value

source ·
pub struct Value<'dom> { /* private fields */ }
Expand description

Value is a node in the DOM tree.

Implementations§

source§

impl<'dom> Value<'dom>

source

pub const fn new_uinit() -> Self

Create a new Value from a null

source

pub const fn new_i64(val: i64) -> Self

Create a new Value from a i64

source

pub fn new_f64(val: f64) -> Option<Self>

Create a new Value from a f64, if not finite return None.

source

pub unsafe fn new_f64_unchecked(val: f64) -> Self

Create a new Value from a f64. Not checking the f64 is finite.

Safety

The f64 must be finite. Because JSON RFC NOT support NaN and Infinity.

source

pub const fn new_u64(val: u64) -> Self

Create a new Value from a u64

source

pub const fn new_bool(val: bool) -> Self

Create a new Value from a bool

source

pub const fn new_object() -> Self

Create a new Value from a empty object

source

pub const fn new_array() -> Self

Create a new Value from a empty array

source

pub fn new_str(val: &str, alloc: &'dom Bump) -> Self

create a new owned string value with the alloctor

source

pub fn new_str_static(val: &'static str) -> Self

create a new string from static

source

pub fn new_str_borrow(val: &str) -> Self

create a new borrow string, lifetime of Value will limited by str

source

pub fn as_array(&'dom self) -> Option<Array<'dom>>

source

pub fn as_object(&'dom self) -> Option<Object<'dom>>

Trait Implementations§

source§

impl<'dom> Debug for Value<'dom>

source§

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

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

impl<'dom> Default for Value<'dom>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl From<bool> for Value<'_>

source§

fn from(val: bool) -> Self

Converts to this type from the input type.
source§

impl From<i64> for Value<'_>

source§

fn from(val: i64) -> Self

Converts to this type from the input type.
source§

impl From<u64> for Value<'_>

source§

fn from(val: u64) -> Self

Converts to this type from the input type.
source§

impl<'dom, I> Index<I> for Value<'dom>
where I: Index,

§

type Output = Value<'dom>

The returned type after indexing.
source§

fn index(&self, index: I) -> &Value<'dom>

Performs the indexing (container[index]) operation. Read more
source§

impl<'a> JsonValue for Value<'a>

§

type ValueType<'dom> = &'dom Value<'dom> where Self: 'dom

source§

fn get_type(&self) -> JsonType

get the type of the JsonValue.
source§

fn as_number(&self) -> Option<Number>

Returns the Number value of the JsonValue if it is a Number.
source§

fn as_i64(&self) -> Option<i64>

Returns the i64 value of the JsonValue if it is a i64.
source§

fn as_u64(&self) -> Option<u64>

Returns the u64 value of the JsonValue if it is a u64.
source§

fn as_f64(&self) -> Option<f64>

Returns the f64 value of the JsonValue if it is a f64.
source§

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

Returns the bool if the JsonValue is a boolean.
source§

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

Returns the str if the JsonValue is a string.
source§

fn pointer<'dom>( &'dom self, path: &JsonPointer<'_> ) -> Option<Self::ValueType<'dom>>

Returns the value from pointer path if the JsonValue is an array or object
source§

fn get<'dom, I: Index>(&self, index: I) -> Option<Self::ValueType<'_>>

Returns the value from index if the JsonValue is an array or object The index may be usize or &str. The usize is for array, the &str is for object.
source§

fn is_boolean(&self) -> bool

Returns true if the JsonValue is a bool.
source§

fn is_true(&self) -> bool

Returns true if the JsonValue is true.
source§

fn is_false(&self) -> bool

Returns true if the JsonValue is false.
source§

fn is_null(&self) -> bool

Returns true if the JsonValue is null.
source§

fn is_number(&self) -> bool

Returns true if the JsonValue is a number.
source§

fn is_str(&self) -> bool

Returns true if the JsonValue is a string.
source§

fn is_array(&self) -> bool

Returns true if the JsonValue is an array.
source§

fn is_object(&self) -> bool

Returns true if the JsonValue is an object.
source§

fn is_f64(&self) -> bool

Returns true if the JsonValue is a f64.
source§

fn is_i64(&self) -> bool

Returns true if the JsonValue is an i64.
source§

fn is_u64(&self) -> bool

Returns true if the JsonValue is a u64.
source§

impl<'dom> Serialize for Value<'dom>

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl TryFrom<f64> for Value<'_>

§

type Error = Error

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

fn try_from(value: f64) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl<'dom> !RefUnwindSafe for Value<'dom>

§

impl<'dom> !Send for Value<'dom>

§

impl<'dom> !Sync for Value<'dom>

§

impl<'dom> Unpin for Value<'dom>

§

impl<'dom> !UnwindSafe for Value<'dom>

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, U> Cast<U> for T
where U: FromCast<T>,

source§

fn cast(self) -> U

Numeric cast from self to T.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> FromCast<T> for T

source§

fn from_cast(t: T) -> T

Numeric cast from T to Self.
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, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.