pub struct RawJson { /* private fields */ }Expand description
An owned piece of JSON text that travels through the SDK unchanged.
It holds whatever value it was built from - an object, an array or a
scalar - as the text the wire carried, so a response field of a shape this
version does not know survives a decode and can be read later with
decode. Two values are equal when their text
is equal, which means equality is textual: {"a":1} and { "a": 1 } are
different values.
§Invariant
The text is always exactly one complete JSON value whose structure is
valid. Nothing builds a RawJson without the codec having established
that, because the text is written into a request body unread: a second
value in it would become a field of the enclosing object. Escapes inside
strings are passed through unchecked: a \u escape with bad hex digits,
or a lone surrogate half, is kept as it was written, and a strict server
refuses the request that carries it. String boundaries are found the same
way either way, so such an escape cannot end a string early.
§Serialization
Inside the SDK the text is spliced into the request body byte for byte:
key order, spacing and the exact spelling of every number are what the
caller or the server wrote. Through any other serializer - serde_json,
for instance - the value is written out as ordinary JSON data instead, so
the data survives while its spelling may not: numbers are re-rendered by
that serializer and insignificant whitespace is dropped.
Which of the two happens is decided by whether the SDK’s own encoder is
running on this thread, not by the type of the serializer, because serde
offers no way to ask a serializer what it is. A RawJson handed to a
foreign serializer from inside a caller’s own Serialize implementation
while the SDK is encoding a request is therefore spliced rather than
transcoded; use as_str there.
Implementations§
Source§impl RawJson
impl RawJson
Sourcepub fn from_value<T>(value: &T) -> Result<Self, EncodeError>
pub fn from_value<T>(value: &T) -> Result<Self, EncodeError>
Encodes value and keeps the resulting JSON text.
§Errors
Returns EncodeError when the value cannot be represented as JSON.
Sourcepub fn decode<'de, T>(&'de self) -> Result<T, DecodeError>where
T: Deserialize<'de>,
pub fn decode<'de, T>(&'de self) -> Result<T, DecodeError>where
T: Deserialize<'de>,
Decodes the held text into T.
It is decode rather than deserialize so that it does not shadow
Deserialize::deserialize, which a caller reaches for when they read
a RawJson out of a document with a codec of their own.
§Errors
Returns DecodeError when the text does not have the shape T
expects, or when it is nested deeper than the decoder allows - which a
value built by from_value can be, since
encoding is not depth limited.
Trait Implementations§
Source§impl Debug for RawJson
impl Debug for RawJson
Source§fn fmt(&self, formatter: &mut Formatter<'_>) -> Result
fn fmt(&self, formatter: &mut Formatter<'_>) -> Result
Prints the JSON text itself, with control characters and the format
characters that reorder or hide text written as Rust escapes: JSON
allows those raw inside a string, the text usually came from a server,
and a {:?} usually ends up in a log line. Backslashes are kept as
they are, since they are the JSON’s own escapes. Display,
as_str and serialization give the text byte for
byte. The default derive would wrap the text in a struct with one
field and quote it a second time.
Source§impl<'de> Deserialize<'de> for RawJson
impl<'de> Deserialize<'de> for RawJson
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
impl Eq for RawJson
impl StructuralPartialEq for RawJson
Auto Trait Implementations§
impl Freeze for RawJson
impl RefUnwindSafe for RawJson
impl Send for RawJson
impl Sync for RawJson
impl Unpin for RawJson
impl UnsafeUnpin for RawJson
impl UnwindSafe for RawJson
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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
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> ⓘ
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more