pub struct Compat<T>(pub T);Available on crate feature
serde only.Expand description
Wrapper that gives any serde type pack-io’s Serialize,
Deserialize and DeserializeView impls, so it can sit anywhere a
pack-io type can: inside a Vec, a map, a tuple, or a derived struct.
The wrapper adds no bytes: Compat(v) encodes exactly like
pack_io::serde::to_vec(&v). Sets inside v follow the adapter’s rules
(see the module docs and sorted_set).
§Examples
use pack_io::serde::Compat;
#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq)]
struct Tag { key: String, value: String }
let tags = vec![Compat(Tag { key: "env".into(), value: "prod".into() })];
let bytes = pack_io::encode(&tags).unwrap();
let back: Vec<Compat<Tag>> = pack_io::decode(&bytes).unwrap();
assert_eq!(back[0].0.value, "prod");Tuple Fields§
§0: TTrait Implementations§
impl<T: Copy> Copy for Compat<T>
Source§impl<T: DeserializeOwned> Deserialize for Compat<T>
impl<T: DeserializeOwned> Deserialize for Compat<T>
Source§impl<'de, T: Deserialize<'de>> DeserializeView<'de> for Compat<T>
impl<'de, T: Deserialize<'de>> DeserializeView<'de> for Compat<T>
impl<T: Eq> Eq for Compat<T>
Source§impl<T: Ord> Ord for Compat<T>
impl<T: Ord> Ord for Compat<T>
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl<T: PartialOrd> PartialOrd for Compat<T>
impl<T: PartialOrd> PartialOrd for Compat<T>
Source§impl<T: Serialize> Serialize for Compat<T>
impl<T: Serialize> Serialize for Compat<T>
Source§fn serialize_slice<E: Encode + ?Sized>(
slice: &[Self],
encoder: &mut E,
) -> Result<()>where
Self: Sized,
fn serialize_slice<E: Encode + ?Sized>(
slice: &[Self],
encoder: &mut E,
) -> Result<()>where
Self: Sized,
Source§fn encoded_len(&self) -> Result<usize>
fn encoded_len(&self) -> Result<usize>
Source§fn encoded_len_slice(slice: &[Self]) -> Result<usize>where
Self: Sized,
fn encoded_len_slice(slice: &[Self]) -> Result<usize>where
Self: Sized,
Exact number of bytes
Serialize::serialize_slice appends for
slice (no length prefix). Counterpart of
Serialize::encoded_len; u8 overrides it to return
slice.len() without iterating. Read moreimpl<T: PartialEq> StructuralPartialEq for Compat<T>
Auto Trait Implementations§
impl<T> Forget for Compat<T>
impl<T> Freeze for Compat<T>where
T: Freeze,
impl<T> Move for Compat<T>
impl<T> RefUnwindSafe for Compat<T>where
T: RefUnwindSafe,
impl<T> Send for Compat<T>where
T: Send,
impl<T> Sync for Compat<T>where
T: Sync,
impl<T> Unpin for Compat<T>where
T: Unpin,
impl<T> UnsafeUnpin for Compat<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Compat<T>where
T: UnwindSafe,
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