pub struct BoxedRawValue(/* private fields */);Expand description
A wrapper around Box<serde_json::value::RawValue> which can be decoded directly from Postgres.
Methods from Deref<Target = RawValue>§
sourcepub fn get(&self) -> &str
pub fn get(&self) -> &str
Access the JSON text underlying a raw value.
Example
use serde::Deserialize;
use serde_json::{Result, value::RawValue};
#[derive(Deserialize)]
struct Response<'a> {
code: u32,
#[serde(borrow)]
payload: &'a RawValue,
}
fn process(input: &str) -> Result<()> {
let response: Response = serde_json::from_str(input)?;
let payload = response.payload.get();
if payload.starts_with('{') {
// handle a payload which is a JSON map
} else {
// handle any other type
}
Ok(())
}
fn main() -> Result<()> {
process(r#" {"code": 200, "payload": {}} "#)?;
Ok(())
}Trait Implementations§
source§impl Clone for BoxedRawValue
impl Clone for BoxedRawValue
source§fn clone(&self) -> BoxedRawValue
fn clone(&self) -> BoxedRawValue
Returns a copy 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 BoxedRawValue
impl Debug for BoxedRawValue
source§impl<'r> Decode<'r, Postgres> for BoxedRawValue
impl<'r> Decode<'r, Postgres> for BoxedRawValue
source§impl Deref for BoxedRawValue
impl Deref for BoxedRawValue
source§impl From<BoxedRawValue> for Box<RawValue>
impl From<BoxedRawValue> for Box<RawValue>
source§fn from(raw_value: BoxedRawValue) -> Self
fn from(raw_value: BoxedRawValue) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl RefUnwindSafe for BoxedRawValue
impl Send for BoxedRawValue
impl Sync for BoxedRawValue
impl Unpin for BoxedRawValue
impl UnwindSafe for BoxedRawValue
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