facet_postcard/
postcard_wrapper.rs

1//! The `Postcard<T>` wrapper type for Postcard serialization/deserialization.
2
3use core::fmt;
4use core::ops::{Deref, DerefMut};
5
6/// A wrapper type for Postcard serialization and deserialization.
7///
8/// Postcard is a `no_std` and embedded-systems friendly compact binary format.
9/// When the `axum` feature is enabled, this type implements Axum's
10/// `FromRequest` and `IntoResponse` traits.
11#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
12pub struct Postcard<T>(pub T);
13
14impl<T> Postcard<T> {
15    /// Consume the wrapper and return the inner value.
16    #[inline]
17    pub fn into_inner(self) -> T {
18        self.0
19    }
20}
21
22impl<T> From<T> for Postcard<T> {
23    #[inline]
24    fn from(inner: T) -> Self {
25        Postcard(inner)
26    }
27}
28
29impl<T> Deref for Postcard<T> {
30    type Target = T;
31
32    #[inline]
33    fn deref(&self) -> &Self::Target {
34        &self.0
35    }
36}
37
38impl<T> DerefMut for Postcard<T> {
39    #[inline]
40    fn deref_mut(&mut self) -> &mut Self::Target {
41        &mut self.0
42    }
43}
44
45impl<T: fmt::Display> fmt::Display for Postcard<T> {
46    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
47        self.0.fmt(f)
48    }
49}