musli_zerocopy/phf/
entry.rs

1use crate::ZeroCopy;
2
3/// An entry which is used when constructing a [`Map<K, V>`].
4///
5/// To construct a map, this type is used to provide [`OwnedBuf`] with a pair of
6/// values.
7///
8/// Note that this primarily exists because tuples are not support. The layout
9/// of a tuple is `repr(Rust)`, so there is no way to construct legal references
10/// to them.
11///
12/// [`Map<K, V>`]: crate::phf::Map
13/// [`OwnedBuf`]: crate::buf::OwnedBuf
14#[derive(Debug, ZeroCopy)]
15#[zero_copy(crate, bounds = {K: ZeroCopy, V: ZeroCopy})]
16#[repr(C)]
17pub(crate) struct Entry<K, V> {
18    /// The first element in the pair.
19    pub(crate) key: K,
20    /// The second element in the pair.
21    pub(crate) value: V,
22}
23
24impl<K, V> Entry<K, V> {
25    /// Construct a new pair.
26    #[cfg(feature = "alloc")]
27    pub(crate) const fn new(key: K, value: V) -> Self {
28        Self { key, value }
29    }
30}