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<'r> Encode<'r, Postgres> for BoxedRawValue
impl<'r> Encode<'r, Postgres> for BoxedRawValue
source§fn encode_by_ref(
&self,
out: &mut <Postgres as HasArguments<'r>>::ArgumentBuffer
) -> IsNull
fn encode_by_ref( &self, out: &mut <Postgres as HasArguments<'r>>::ArgumentBuffer ) -> IsNull
§fn encode(self, buf: &mut <DB as HasArguments<'q>>::ArgumentBuffer) -> IsNullwhere
Self: Sized,
fn encode(self, buf: &mut <DB as HasArguments<'q>>::ArgumentBuffer) -> IsNullwhere Self: Sized,
Writes the value of
self
into buf
in the expected format for the database.fn produces(&self) -> Option<<DB as Database>::TypeInfo>
fn size_hint(&self) -> usize
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.
source§impl PgHasArrayType for BoxedRawValue
impl PgHasArrayType for BoxedRawValue
fn array_type_info() -> PgTypeInfo
fn array_compatible(ty: &PgTypeInfo) -> bool
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