hmap_serde/hmap/
mod.rs

1use std::ops::{Deref, DerefMut};
2
3use frunk_core::hlist::HNil;
4
5mod de;
6mod ser;
7#[cfg(test)]
8mod tests;
9
10#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
11#[repr(transparent)]
12pub struct HMap<T>(pub T);
13
14impl<T> HMap<T> {
15    #[allow(clippy::missing_const_for_fn)] // const deref ptr is unstable
16    fn ref_cast(from: &T) -> &Self {
17        // SAFETY HMap is repr(transparent)
18        unsafe { &*(from as *const T).cast() }
19    }
20}
21
22impl<T> Deref for HMap<T> {
23    type Target = T;
24
25    #[inline]
26    fn deref(&self) -> &Self::Target {
27        &self.0
28    }
29}
30
31impl<T> DerefMut for HMap<T> {
32    #[inline]
33    fn deref_mut(&mut self) -> &mut Self::Target {
34        &mut self.0
35    }
36}
37
38impl Default for HMap<HNil> {
39    fn default() -> Self {
40        Self(HNil)
41    }
42}