musli_zerocopy/buf/
bind.rs

1use crate::buf::Buf;
2use crate::error::Error;
3
4mod sealed {
5    use crate::endian::ByteOrder;
6    use crate::pointer::Size;
7    use crate::traits::ZeroCopy;
8
9    pub trait Sealed {}
10
11    impl<K, V, E, O> Sealed for crate::phf::map::MapRef<K, V, E, O>
12    where
13        K: ZeroCopy,
14        V: ZeroCopy,
15        E: ByteOrder,
16        O: Size,
17    {
18    }
19
20    impl<K, V, E, O> Sealed for crate::swiss::map::MapRef<K, V, E, O>
21    where
22        K: ZeroCopy,
23        V: ZeroCopy,
24        E: ByteOrder,
25        O: Size,
26    {
27    }
28
29    impl<T, E, O> Sealed for crate::phf::set::SetRef<T, E, O>
30    where
31        T: ZeroCopy,
32        E: ByteOrder,
33        O: Size,
34    {
35    }
36
37    impl<T, E, O> Sealed for crate::swiss::set::SetRef<T, E, O>
38    where
39        T: ZeroCopy,
40        E: ByteOrder,
41        O: Size,
42    {
43    }
44}
45
46/// Trait used for binding a reference to a [`Buf`] through [`Buf::bind()`].
47///
48/// This is used to make reference types easier to work with. Bound values
49/// provide more natural APIs and can dereference to the underlying types.
50pub trait Bindable: self::sealed::Sealed {
51    /// The target of the binding.
52    type Bound<'a>
53    where
54        Self: 'a;
55
56    /// Bind the current value to a [`Buf`].
57    fn bind(self, buf: &Buf) -> Result<Self::Bound<'_>, Error>;
58}