facet_xml/
xml.rs

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