[go: up one dir, main page]

Struct OwnedLazyValue

Source
pub struct OwnedLazyValue(/* private fields */);
Expand description

OwnedLazyValue wrappers a unparsed raw JSON text. It is owned and support Get, Set

It can be converted from LazyValue. It can be used for serde.

Default value is a raw JSON text null.

§Examples

use sonic_rs::{get, JsonValueTrait, OwnedLazyValue};

// get a lazyvalue from a json, the "a"'s value will not be parsed
let input = r#"{
 "a": "hello world",
 "b": true,
 "c": [0, 1, 2],
 "d": {
    "sonic": "rs"
  }
}"#;

let own_a = OwnedLazyValue::from(get(input, &["a"]).unwrap());
let own_c = OwnedLazyValue::from(get(input, &["c"]).unwrap());

// use as_xx to get the parsed value
assert_eq!(own_a.as_str().unwrap(), "hello world");
assert_eq!(own_c.as_str(), None);
assert!(own_c.is_array());

§Serde Examples

use serde::{Deserialize, Serialize};

#[derive(Debug, Deserialize, Serialize)]
struct TestLazyValue<'a> {
    #[serde(borrow)]
    borrowed_lv: LazyValue<'a>,
    owned_lv: OwnedLazyValue,
}

let input = r#"{ "borrowed_lv": "hello", "owned_lv": "world" }"#;

let data: TestLazyValue = sonic_rs::from_str(input).unwrap();
assert_eq!(data.borrowed_lv.as_raw_str(), "\"hello\"");

Implementations§

Source§

impl OwnedLazyValue

Source

pub fn take(&mut self) -> Self

Trait Implementations§

Source§

impl Clone for OwnedLazyValue

Source§

fn clone(&self) -> OwnedLazyValue

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 Debug for OwnedLazyValue

Source§

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

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

impl Default for OwnedLazyValue

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for OwnedLazyValue

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for OwnedLazyValue

Source§

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

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

impl From<()> for OwnedLazyValue

Source§

fn from(_: ()) -> Self

Converts to this type from the input type.
Source§

impl From<LazyArray> for OwnedLazyValue

Source§

fn from(v: LazyArray) -> Self

Converts to this type from the input type.
Source§

impl From<LazyObject> for OwnedLazyValue

Source§

fn from(v: LazyObject) -> Self

Converts to this type from the input type.
Source§

impl<'de> From<LazyValue<'de>> for OwnedLazyValue

Source§

fn from(lv: LazyValue<'de>) -> Self

Converts to this type from the input type.
Source§

impl From<Number> for OwnedLazyValue

Source§

fn from(number: Number) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<(FastStr, OwnedLazyValue)>> for OwnedLazyValue

Source§

fn from(v: Vec<(FastStr, OwnedLazyValue)>) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<OwnedLazyValue>> for OwnedLazyValue

Source§

fn from(v: Vec<OwnedLazyValue>) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for OwnedLazyValue

Source§

fn from(v: bool) -> Self

Converts to this type from the input type.
Source§

impl JsonContainerTrait for OwnedLazyValue

Source§

type ArrayType = LazyArray

Source§

type ObjectType = LazyObject

Source§

fn as_array(&self) -> Option<&Self::ArrayType>

Returns the array if self is an array. Read more
Source§

fn as_object(&self) -> Option<&Self::ObjectType>

Returns the object if self is an object. Read more
Source§

impl JsonValueMutTrait for OwnedLazyValue

Source§

type ValueType = OwnedLazyValue

Source§

type ArrayType = LazyArray

Source§

type ObjectType = LazyObject

Source§

fn as_object_mut(&mut self) -> Option<&mut LazyObject>

Returns the mutable object if self is an object. Read more
Source§

fn as_array_mut(&mut self) -> Option<&mut LazyArray>

Returns the mutable array if self is an array. Read more
Source§

fn get_mut<I: Index>(&mut self, index: I) -> Option<&mut OwnedLazyValue>

Mutably index into a JSON array or map. A string-like index can be used to access a value in a map, and a usize index can be used to access an element of an array. Read more
Source§

fn pointer_mut<P: IntoIterator>( &mut self, path: P, ) -> Option<&mut OwnedLazyValue>
where P::Item: Index,

Looks up a value by a path. Read more
Source§

impl JsonValueTrait for OwnedLazyValue

Source§

type ValueType<'v> = &'v OwnedLazyValue

Source§

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

Returns the bool if self is a boolean. Read more
Source§

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

Returns the Number if self is a Number. Read more
Source§

fn as_raw_number(&self) -> Option<RawNumber>

Returns the RawNumber without precision loss if self is a Number.
Source§

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

Returns the str if self is a string. Read more
Source§

fn get_type(&self) -> JsonType

Gets the type of the value. Returns JsonType::Null as default if self is Option::None or Result::Err(_). Read more
Source§

fn get<I: Index>(&self, index: I) -> Option<&OwnedLazyValue>

Index into a JSON array or map. A string-like index can be used to access a value in a map, and a usize index can be used to access an element of an array. Read more
Source§

fn pointer<P: IntoIterator>(&self, path: P) -> Option<&OwnedLazyValue>
where P::Item: Index,

Looks up a value by a path. Read more
Source§

fn is_boolean(&self) -> bool

Returns true if the value is a bool. Read more
Source§

fn is_true(&self) -> bool

Returns true if the value is true. Read more
Source§

fn is_false(&self) -> bool

Returns true if the value is false. Read more
Source§

fn is_null(&self) -> bool

Returns true if the self value is null. Read more
Source§

fn is_number(&self) -> bool

Returns true if the value is a number. Read more
Source§

fn is_str(&self) -> bool

Returns true if the value is a string. Read more
Source§

fn is_array(&self) -> bool

Returns true if the value is an array. Read more
Source§

fn is_object(&self) -> bool

Returns true if the value is an object. Read more
Source§

fn is_f64(&self) -> bool

Returns true if the value is a number and it is an f64. It will returns false if the value is a u64 or i64. Read more
Source§

fn is_i64(&self) -> bool

Returns true if the value is a integer number and it between i64::MIN and i64::MAX Read more
Source§

fn is_u64(&self) -> bool

Returns true if the value is a integer number and it between 0 and i64::MAX Read more
Source§

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

If self meets is_i64, represent it as i64 if possible. Returns None otherwise. Read more
Source§

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

If self meets is_i64, represent it as u64 if possible. Returns None otherwise. Read more
Source§

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

If self is a number, represent it as f64 if possible. Returns None otherwise. The integer number will be converted to f64. Read more
Source§

impl Serialize for OwnedLazyValue

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

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,