musli_core/hint/
map_hint.rs

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

/// A hint passed in when encoding a map.
#[non_exhaustive]
pub struct MapHint {
    /// The size for the map being encoded.
    pub size: usize,
}

impl MapHint {
    /// Create a new struct hint with the specified size.
    ///
    /// # Examples
    ///
    /// ```
    /// use musli::hint::MapHint;
    ///
    /// static HINT: MapHint = MapHint::with_size(16);
    ///
    /// assert_eq!(HINT.size, 16);
    /// ```
    #[inline]
    pub const fn with_size(size: usize) -> Self {
        Self { size }
    }

    /// Return the size hint that corresponds to this overall hint.
    #[inline]
    pub fn size_hint(&self) -> SizeHint {
        SizeHint::exact(self.size)
    }
}