pub struct Raw<'a, F: RawFormat> { /* private fields */ }Expand description
A value encoded in the format F.
A raw value holds a value in the encoding of a format, for instance
JSON text with deser_json::RawJson. It can be deserialized later
(with deserialize), stored or written out again
unchanged:
- If it’s deserialized from the format
F, it holds the input of the value as it is. The format only validates the value and does not produce its events, which is fast. With theBorrowedadapter the input is borrowed. - Otherwise (from another format or where the format cannot pass on
the input, see below) the value is encoded in the format
F. The encoding can lose information thatFcannot express (bytes in JSON for instance). To keep a value of any format without interpreting it, useRecording.
When serialized with the format F, the encoded value is written as it
is. Other formats serialize the value it holds.
The input of values can only be passed on if the format knows before
the value starts that a raw value is wanted. Derived structs (for their
first 64 fields), maps, sequences, Option and Box ask for it.
Values in other places (like the fields of flattened structs, the
variants of enums and values that are buffered, for instance for
untagged enums) are encoded.
Like Cow, raw values are deserialized owned, so a Raw<'static, F>
can be deserialized from any data.
Implementations§
Source§impl<'a, F: RawFormat> Raw<'a, F>
impl<'a, F: RawFormat> Raw<'a, F>
Sourcepub fn new<B: Into<Cow<'a, [u8]>>>(bytes: B) -> Result<Raw<'a, F>, Error>
pub fn new<B: Into<Cow<'a, [u8]>>>(bytes: B) -> Result<Raw<'a, F>, Error>
Creates a raw value from its encoding.
The value is validated.
Sourcepub fn encode<T: Serialize + ?Sized>(
value: &T,
) -> Result<Raw<'static, F>, Error>
pub fn encode<T: Serialize + ?Sized>( value: &T, ) -> Result<Raw<'static, F>, Error>
Encodes a value.
Sourcepub fn is_borrowed(&self) -> bool
pub fn is_borrowed(&self) -> bool
Returns true if the value borrows from the data it was
deserialized from.
Sourcepub fn replay<'x>(
&'x self,
sink: SinkHandle<'_, 'x>,
state: &mut State,
) -> Result<(), Error>
pub fn replay<'x>( &'x self, sink: SinkHandle<'_, 'x>, state: &mut State, ) -> Result<(), Error>
Replays the value into a sink.
The value is parsed, the sink can borrow its data.
Sourcepub fn deserialize<'x, T: Deserialize<'x>>(&'x self) -> Result<T, Error>
pub fn deserialize<'x, T: Deserialize<'x>>(&'x self) -> Result<T, Error>
Deserializes the value.
The value can borrow from the raw value (and the data it borrows).
Sourcepub fn into_owned(self) -> Raw<'static, F>
pub fn into_owned(self) -> Raw<'static, F>
Detaches the value from the data it borrows.
Trait Implementations§
Source§impl<'de: 'a, 'a, F: RawFormat> Deserialize<'de, Raw<'a, F>> for Borrowed
Borrows raw values from the data if the format passes it on borrowed.
impl<'de: 'a, 'a, F: RawFormat> Deserialize<'de, Raw<'a, F>> for Borrowed
Borrows raw values from the data if the format passes it on borrowed.
Source§fn deserialize_into<'out>(
out: &'out mut Option<Raw<'a, F>>,
state: &mut State,
) -> SinkHandle<'out, 'de>
fn deserialize_into<'out>( out: &'out mut Option<Raw<'a, F>>, state: &mut State, ) -> SinkHandle<'out, 'de>
Source§fn expecting() -> Cow<'static, str>
fn expecting() -> Cow<'static, str>
Source§fn deserialize_atom(
slot: &mut Slot<T, Self>,
atom: Atom<'_>,
state: &mut State,
) -> Result<(), Error>
fn deserialize_atom( slot: &mut Slot<T, Self>, atom: Atom<'_>, state: &mut State, ) -> Result<(), Error>
Source§fn deserialize_borrowed_atom(
slot: &mut Slot<T, Self>,
atom: Atom<'de>,
state: &mut State,
) -> Result<(), Error>
fn deserialize_borrowed_atom( slot: &mut Slot<T, Self>, atom: Atom<'de>, state: &mut State, ) -> Result<(), Error>
Source§fn describe_type(d: &mut dyn Describe)
fn describe_type(d: &mut dyn Describe)
Source§fn initial_value() -> Option<T>
fn initial_value() -> Option<T>
Source§fn deserialize_update<'out>(
value: &'out mut T,
state: &mut State,
) -> SinkHandle<'out, 'de>
fn deserialize_update<'out>( value: &'out mut T, state: &mut State, ) -> SinkHandle<'out, 'de>
Source§impl<'de, 'a, F: RawFormat> Deserialize<'de> for Raw<'a, F>
Raw values are deserialized owned so that Raw<'static, F> can be
deserialized from any data. To borrow use the
Borrowed adapter.
impl<'de, 'a, F: RawFormat> Deserialize<'de> for Raw<'a, F>
Raw values are deserialized owned so that Raw<'static, F> can be
deserialized from any data. To borrow use the
Borrowed adapter.
Source§fn deserialize_into<'out>(
out: &'out mut Option<Self>,
state: &mut State,
) -> SinkHandle<'out, 'de>
fn deserialize_into<'out>( out: &'out mut Option<Self>, state: &mut State, ) -> SinkHandle<'out, 'de>
Source§fn expecting() -> Cow<'static, str>
fn expecting() -> Cow<'static, str>
Source§fn deserialize_atom(
slot: &mut Slot<T, Self>,
atom: Atom<'_>,
state: &mut State,
) -> Result<(), Error>
fn deserialize_atom( slot: &mut Slot<T, Self>, atom: Atom<'_>, state: &mut State, ) -> Result<(), Error>
Source§fn deserialize_borrowed_atom(
slot: &mut Slot<T, Self>,
atom: Atom<'de>,
state: &mut State,
) -> Result<(), Error>
fn deserialize_borrowed_atom( slot: &mut Slot<T, Self>, atom: Atom<'de>, state: &mut State, ) -> Result<(), Error>
Source§fn describe_type(d: &mut dyn Describe)
fn describe_type(d: &mut dyn Describe)
Source§fn initial_value() -> Option<T>
fn initial_value() -> Option<T>
Source§fn deserialize_update<'out>(
value: &'out mut T,
state: &mut State,
) -> SinkHandle<'out, 'de>
fn deserialize_update<'out>( value: &'out mut T, state: &mut State, ) -> SinkHandle<'out, 'de>
impl<F: RawFormat> Eq for Raw<'_, F>
Source§impl<F: RawFormat> PartialEq for Raw<'_, F>
Raw values are equal if their encodings are equal.
impl<F: RawFormat> PartialEq for Raw<'_, F>
Raw values are equal if their encodings are equal.
Source§impl<F: RawFormat> Serialize for Raw<'_, F>
Serialized with the format F, the encoded value is written as it is.
Other formats serialize the value it holds.
impl<F: RawFormat> Serialize for Raw<'_, F>
Serialized with the format F, the encoded value is written as it is.
Other formats serialize the value it holds.
Source§fn serialize<'a>(value: &'a Self, state: &mut State) -> Result<Emit<'a>, Error>
fn serialize<'a>(value: &'a Self, state: &mut State) -> Result<Emit<'a>, Error>
Source§fn finish(value: &T, state: &mut State) -> Result<(), Error>
fn finish(value: &T, state: &mut State) -> Result<(), Error>
Source§fn container_shape(value: &T) -> ContainerShape
fn container_shape(value: &T) -> ContainerShape
Source§impl<'a, F: RawFormat> Serialize<Raw<'a, F>> for Borrowed
impl<'a, F: RawFormat> Serialize<Raw<'a, F>> for Borrowed
Source§fn serialize<'x>(
value: &'x Raw<'a, F>,
state: &mut State,
) -> Result<Emit<'x>, Error>
fn serialize<'x>( value: &'x Raw<'a, F>, state: &mut State, ) -> Result<Emit<'x>, Error>
Source§fn finish(value: &T, state: &mut State) -> Result<(), Error>
fn finish(value: &T, state: &mut State) -> Result<(), Error>
Source§fn container_shape(value: &T) -> ContainerShape
fn container_shape(value: &T) -> ContainerShape
Auto Trait Implementations§
impl<'a, F> !RefUnwindSafe for Raw<'a, F>
impl<'a, F> !UnwindSafe for Raw<'a, F>
impl<'a, F> Freeze for Raw<'a, F>
impl<'a, F> Send for Raw<'a, F>
impl<'a, F> Sync for Raw<'a, F>
impl<'a, F> Unpin for Raw<'a, F>
impl<'a, F> UnsafeUnpin for Raw<'a, F>
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
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.