pub struct BytesFallback<F>(/* private fields */);Expand description
Represents bytes as bytes, with a fallback for formats without native bytes.
The bytes are serialized as bytes which carry the format F as
fallback (see Bytes::fallback). Formats with native bytes (like CBOR)
write them as bytes, formats without native bytes (like JSON and TOML)
write them in F: strings in an encoding or sequences
of integers for IntSeq. When deserializing native bytes and the
representation of F are accepted. It supports the types of
BytesBuf.
use deser::adapters::{Base64Url, BytesFallback, IntSeq};
use deser::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
pub struct Blob {
// URL-safe base64 in JSON and TOML, bytes in CBOR
#[deser(as = BytesFallback<Base64Url>)]
sha1: [u8; 20],
#[deser(as = Option<BytesFallback<Base64Url>>)]
signature: Option<Vec<u8>>,
// `[1, 2]` in JSON and TOML, bytes in CBOR
#[deser(as = BytesFallback<IntSeq>)]
legacy: Vec<u8>,
}To use an encoding in all formats, use the encoding as adapter (for
instance #[deser(as = Base64Url)]). To change the representation of all
bytes, configure the format instead.
Trait Implementations§
Source§impl<'de, T: BytesBuf, F: BytesFallbackFormat> DeserializeAs<'de, T> for BytesFallback<F>
impl<'de, T: BytesBuf, F: BytesFallbackFormat> DeserializeAs<'de, T> for BytesFallback<F>
Source§fn deserialize_into_as<'out>(
out: &'out mut Option<T>,
state: &mut State,
) -> SinkHandle<'out, 'de>
fn deserialize_into_as<'out>( out: &'out mut Option<T>, state: &mut State, ) -> SinkHandle<'out, 'de>
Creates a sink that deserializes the value into the given slot. Read more
Source§fn initial_value_as() -> Option<T>
fn initial_value_as() -> Option<T>
Provides the value of a missing struct field. Read more
Source§fn deserialize_update_as<'out>(
value: &'out mut T,
state: &mut State,
) -> SinkHandle<'out, 'de>
fn deserialize_update_as<'out>( value: &'out mut T, state: &mut State, ) -> SinkHandle<'out, 'de>
Creates a sink that updates an existing value. Read more
Source§impl<T: BytesBuf, F: BytesFallbackFormat> SerializeAs<T> for BytesFallback<F>
impl<T: BytesBuf, F: BytesFallbackFormat> SerializeAs<T> for BytesFallback<F>
Source§fn serialize_as<'a>(
value: &'a T,
_state: &mut State,
) -> Result<Chunk<'a>, Error>
fn serialize_as<'a>( value: &'a T, _state: &mut State, ) -> Result<Chunk<'a>, Error>
Serializes the value. Read more
Source§fn finish_as(value: &T, state: &mut State) -> Result<(), Error>
fn finish_as(value: &T, state: &mut State) -> Result<(), Error>
Invoked after the serialization finished. Read more
Source§fn is_optional_as(value: &T) -> bool
fn is_optional_as(value: &T) -> bool
Checks if the value represents an optional value. Read more
Source§fn container_shape_as(value: &T) -> ContainerShape
fn container_shape_as(value: &T) -> ContainerShape
Returns the shape of the value if it’s a map or sequence. Read more
Auto Trait Implementations§
impl<F> Freeze for BytesFallback<F>
impl<F> RefUnwindSafe for BytesFallback<F>
impl<F> Send for BytesFallback<F>
impl<F> Sync for BytesFallback<F>
impl<F> Unpin for BytesFallback<F>
impl<F> UnsafeUnpin for BytesFallback<F>
impl<F> UnwindSafe for BytesFallback<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
Mutably borrows from an owned value. Read more