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
use crate::ZeroCopy;

/// An entry which is used when constructing a [`Map<K, V>`].
///
/// To construct a map, this type is used to provide [`OwnedBuf`] with a pair
/// of values.
///
/// Note that this primarily exists because tuples are not support. The layout
/// of a tuple is `repr(Rust)`, so there is no way to construct legal references
/// to them.
///
/// [`Map<K, V>`]: crate::map::Map
/// [`OwnedBuf`]: crate::buf::OwnedBuf
#[derive(Debug, ZeroCopy)]
#[zero_copy(crate, bounds = {K: ZeroCopy, V: ZeroCopy})]
#[repr(C)]
pub(crate) struct Entry<K, V> {
    /// The first element in the pair.
    pub(crate) key: K,
    /// The second element in the pair.
    pub(crate) value: V,
}

impl<K, V> Entry<K, V> {
    /// Construct a new pair.
    #[cfg(feature = "alloc")]
    pub(crate) const fn new(key: K, value: V) -> Self {
        Self { key, value }
    }
}