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>§
pub const NULL: &'static RawValue
pub const TRUE: &'static RawValue
pub const FALSE: &'static 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 Database>::ArgumentBuffer<'r>,
) -> Result<IsNull, Box<dyn Error + Send + Sync>>
fn encode_by_ref( &self, out: &mut <Postgres as Database>::ArgumentBuffer<'r>, ) -> Result<IsNull, Box<dyn Error + Send + Sync>>
Source§fn encode(
self,
buf: &mut <DB as Database>::ArgumentBuffer<'q>,
) -> Result<IsNull, Box<dyn Error + Sync + Send>>where
Self: Sized,
fn encode(
self,
buf: &mut <DB as Database>::ArgumentBuffer<'q>,
) -> Result<IsNull, Box<dyn Error + Sync + Send>>where
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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more