1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use crate::buf::Buf;
use crate::error::Error;

mod sealed {
    use crate::endian::ByteOrder;
    use crate::pointer::Size;
    use crate::traits::ZeroCopy;

    pub trait Sealed {}

    impl<K, V, E: ByteOrder, O: Size> Sealed for crate::phf::map::MapRef<K, V, E, O>
    where
        K: ZeroCopy,
        V: ZeroCopy,
    {
    }

    impl<K, V, E: ByteOrder, O: Size> Sealed for crate::swiss::map::MapRef<K, V, E, O>
    where
        K: ZeroCopy,
        V: ZeroCopy,
    {
    }

    impl<T, E: ByteOrder, O: Size> Sealed for crate::phf::set::SetRef<T, E, O> where T: ZeroCopy {}

    impl<T, E: ByteOrder, O: Size> Sealed for crate::swiss::set::SetRef<T, E, O> where T: ZeroCopy {}
}

/// Trait used for binding a reference to a [`Buf`] through [`Buf::bind()`].
///
/// This is used to make reference types easier to work with. Bound values
/// provide more natural APIs and can dereference to the underlying types.
pub trait Bindable: self::sealed::Sealed {
    /// The target of the binding.
    type Bound<'a>
    where
        Self: 'a;

    /// Bind the current value to a [`Buf`].
    fn bind(self, buf: &Buf) -> Result<Self::Bound<'_>, Error>;
}