Skip to main content

Raw

Struct Raw 

Source
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 the Borrowed adapter 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 that F cannot express (bytes in JSON for instance). To keep a value of any format without interpreting it, use Recording.

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>

Source

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.

Source

pub fn encode<T: Serialize + ?Sized>( value: &T, ) -> Result<Raw<'static, F>, Error>

Encodes a value.

Source

pub fn as_bytes(&self) -> &[u8] ⓘ

Returns the encoded value.

Source

pub fn is_borrowed(&self) -> bool

Returns true if the value borrows from the data it was deserialized from.

Source

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.

Source

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).

Source

pub fn into_owned(self) -> Raw<'static, F>

Detaches the value from the data it borrows.

Source§

impl<F: TextRawFormat> Raw<'_, F>

Source

pub fn get(&self) -> &str

Returns the encoded value as text.

Trait Implementations§

Source§

impl<F: RawFormat> Clone for Raw<'_, F>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<F: RawFormat> Debug for Raw<'_, F>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
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.

Source§

fn deserialize_into<'out>( out: &'out mut Option<Raw<'a, F>>, state: &mut State, ) -> SinkHandle<'out, 'de>

Creates a sink that deserializes the value into the given slot. Read more
Source§

fn expecting() -> Cow<'static, str>

Returns what the value expects, for error messages. Read more
Source§

fn deserialize_atom( slot: &mut Slot<T, Self>, atom: Atom<'_>, state: &mut State, ) -> Result<(), Error>

Deserializes an atom into the slot. Read more
Source§

fn deserialize_borrowed_atom( slot: &mut Slot<T, Self>, atom: Atom<'de>, state: &mut State, ) -> Result<(), Error>

Deserializes an atom that borrows from the data being deserialized into the slot. Read more
Source§

fn describe_type(d: &mut dyn Describe)

Describes the Rust shape of the type. Read more
Source§

fn initial_value() -> Option<T>

Provides the value of a missing struct field. Read more
Source§

fn deserialize_update<'out>( value: &'out mut T, state: &mut State, ) -> SinkHandle<'out, 'de>

Creates a sink that updates an existing value. Read more
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.

Source§

fn deserialize_into<'out>( out: &'out mut Option<Self>, state: &mut State, ) -> SinkHandle<'out, 'de>

Creates a sink that deserializes the value into the given slot. Read more
Source§

fn expecting() -> Cow<'static, str>

Returns what the value expects, for error messages. Read more
Source§

fn deserialize_atom( slot: &mut Slot<T, Self>, atom: Atom<'_>, state: &mut State, ) -> Result<(), Error>

Deserializes an atom into the slot. Read more
Source§

fn deserialize_borrowed_atom( slot: &mut Slot<T, Self>, atom: Atom<'de>, state: &mut State, ) -> Result<(), Error>

Deserializes an atom that borrows from the data being deserialized into the slot. Read more
Source§

fn describe_type(d: &mut dyn Describe)

Describes the Rust shape of the type. Read more
Source§

fn initial_value() -> Option<T>

Provides the value of a missing struct field. Read more
Source§

fn deserialize_update<'out>( value: &'out mut T, state: &mut State, ) -> SinkHandle<'out, 'de>

Creates a sink that updates an existing value. Read more
Source§

impl<F: RawFormat> Eq for Raw<'_, F>

Source§

impl<F: RawFormat> Hash for Raw<'_, F>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<F: RawFormat> PartialEq for Raw<'_, F>

Raw values are equal if their encodings are equal.

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
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.

Source§

fn serialize<'a>(value: &'a Self, state: &mut State) -> Result<Emit<'a>, Error>

Serializes the value.
Source§

fn finish(value: &T, state: &mut State) -> Result<(), Error>

Invoked after the serialization finished. Read more
Source§

fn is_optional(value: &T) -> bool

Checks if the value represents an optional value. Read more
Source§

fn describe(value: &T, d: &mut dyn Describe)

Describes the Rust shape of the value. Read more
Source§

fn container_shape(value: &T) -> ContainerShape

Returns the shape of the value if it’s a map or sequence. Read more
Source§

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>

Serializes the value.
Source§

fn finish(value: &T, state: &mut State) -> Result<(), Error>

Invoked after the serialization finished. Read more
Source§

fn is_optional(value: &T) -> bool

Checks if the value represents an optional value. Read more
Source§

fn describe(value: &T, d: &mut dyn Describe)

Describes the Rust shape of the value. Read more
Source§

fn container_shape(value: &T) -> ContainerShape

Returns the shape of the value if it’s a map or sequence. Read more

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>
where PhantomData<fn() -> F>: Freeze,

§

impl<'a, F> Send for Raw<'a, F>
where PhantomData<fn() -> F>: Send,

§

impl<'a, F> Sync for Raw<'a, F>
where PhantomData<fn() -> F>: Sync,

§

impl<'a, F> Unpin for Raw<'a, F>
where PhantomData<fn() -> F>: Unpin,

§

impl<'a, F> UnsafeUnpin for Raw<'a, F>
where PhantomData<fn() -> F>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.