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§fn decode(
value: <Postgres as HasValueRef<'r>>::ValueRef
) -> Result<Self, BoxDynError>
fn decode( value: <Postgres as HasValueRef<'r>>::ValueRef ) -> Result<Self, BoxDynError>
Decode a new value of this type using a raw value from the database.
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
source§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 PartialEq for BoxedRawValue
impl PartialEq for BoxedRawValue
source§impl PgHasArrayType for BoxedRawValue
impl PgHasArrayType for BoxedRawValue
fn array_type_info() -> PgTypeInfo
fn array_compatible(ty: &PgTypeInfo) -> bool
source§impl Type<Postgres> for BoxedRawValue
impl Type<Postgres> for BoxedRawValue
source§fn type_info() -> PgTypeInfo
fn type_info() -> PgTypeInfo
Returns the canonical SQL type for this Rust type. Read more
source§fn compatible(ty: &PgTypeInfo) -> bool
fn compatible(ty: &PgTypeInfo) -> bool
Determines if this Rust type is compatible with the given SQL type. Read more
impl Eq for BoxedRawValue
Auto Trait Implementations§
impl Freeze for BoxedRawValue
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
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.