pub enum ValueRef<'a> {
Null,
Bool(bool),
Number(Number),
String(&'a str),
Array(&'a Array),
Object(&'a Object),
}
Expand description
ValueRef is a immutable reference helper for Value
.
§Example
use sonic_rs::{ValueRef, json, JsonValueTrait};
let v = json!({
"name": "Xiaoming",
"age": 18,
});
match v.as_ref() {
ValueRef::Object(obj) => {
assert_eq!(obj.get(&"name").unwrap().as_str().unwrap(), "Xiaoming");
assert_eq!(obj.get(&"age").unwrap().as_i64().unwrap(), 18);
},
_ => unreachable!(),
}
Variants§
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for ValueRef<'a>
impl<'a> !RefUnwindSafe for ValueRef<'a>
impl<'a> Send for ValueRef<'a>
impl<'a> Sync for ValueRef<'a>
impl<'a> Unpin for ValueRef<'a>
impl<'a> !UnwindSafe for ValueRef<'a>
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