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§
Trait Implementations§
Source§impl Clone for OwnedLazyValue
impl Clone for OwnedLazyValue
Source§fn clone(&self) -> OwnedLazyValue
fn clone(&self) -> OwnedLazyValue
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for OwnedLazyValue
impl Debug for OwnedLazyValue
Source§impl Default for OwnedLazyValue
impl Default for OwnedLazyValue
Source§impl<'de> Deserialize<'de> for OwnedLazyValue
impl<'de> Deserialize<'de> for OwnedLazyValue
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
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
impl Display for OwnedLazyValue
Source§impl From<()> for OwnedLazyValue
impl From<()> for OwnedLazyValue
Source§impl From<LazyArray> for OwnedLazyValue
impl From<LazyArray> for OwnedLazyValue
Source§impl From<LazyObject> for OwnedLazyValue
impl From<LazyObject> for OwnedLazyValue
Source§fn from(v: LazyObject) -> Self
fn from(v: LazyObject) -> Self
Converts to this type from the input type.
Source§impl<'de> From<LazyValue<'de>> for OwnedLazyValue
impl<'de> From<LazyValue<'de>> for OwnedLazyValue
Source§impl From<Number> for OwnedLazyValue
impl From<Number> for OwnedLazyValue
Source§impl From<Vec<(FastStr, OwnedLazyValue)>> for OwnedLazyValue
impl From<Vec<(FastStr, OwnedLazyValue)>> for OwnedLazyValue
Source§impl From<Vec<OwnedLazyValue>> for OwnedLazyValue
impl From<Vec<OwnedLazyValue>> for OwnedLazyValue
Source§fn from(v: Vec<OwnedLazyValue>) -> Self
fn from(v: Vec<OwnedLazyValue>) -> Self
Converts to this type from the input type.
Source§impl From<bool> for OwnedLazyValue
impl From<bool> for OwnedLazyValue
Source§impl JsonContainerTrait for OwnedLazyValue
impl JsonContainerTrait for OwnedLazyValue
Source§impl JsonValueMutTrait for OwnedLazyValue
impl JsonValueMutTrait for OwnedLazyValue
type ValueType = OwnedLazyValue
type ArrayType = LazyArray
type ObjectType = LazyObject
Source§fn as_object_mut(&mut self) -> Option<&mut LazyObject>
fn as_object_mut(&mut self) -> Option<&mut LazyObject>
Source§fn as_array_mut(&mut self) -> Option<&mut LazyArray>
fn as_array_mut(&mut self) -> Option<&mut LazyArray>
Source§fn get_mut<I: Index>(&mut self, index: I) -> Option<&mut OwnedLazyValue>
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>
fn pointer_mut<P: IntoIterator>( &mut self, path: P, ) -> Option<&mut OwnedLazyValue>
Looks up a value by a path. Read more
Source§impl JsonValueTrait for OwnedLazyValue
impl JsonValueTrait for OwnedLazyValue
type ValueType<'v> = &'v OwnedLazyValue
Source§fn as_raw_number(&self) -> Option<RawNumber>
fn as_raw_number(&self) -> Option<RawNumber>
Source§fn get_type(&self) -> JsonType
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 moreSource§fn get<I: Index>(&self, index: I) -> Option<&OwnedLazyValue>
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>
fn pointer<P: IntoIterator>(&self, path: P) -> Option<&OwnedLazyValue>
Looks up a value by a path. Read more
Source§fn is_boolean(&self) -> bool
fn is_boolean(&self) -> bool
Returns true if the value is a
bool. Read moreSource§fn is_f64(&self) -> bool
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 moreAuto Trait Implementations§
impl !Freeze for OwnedLazyValue
impl RefUnwindSafe for OwnedLazyValue
impl Send for OwnedLazyValue
impl Sync for OwnedLazyValue
impl Unpin for OwnedLazyValue
impl UnwindSafe for OwnedLazyValue
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more