musli_core/hint/
map_hint.rs

1use crate::de::SizeHint;
2
3/// A hint passed in when encoding a map.
4#[non_exhaustive]
5pub struct MapHint {
6    /// The size for the map being encoded.
7    pub size: usize,
8}
9
10impl MapHint {
11    /// Create a new struct hint with the specified size.
12    ///
13    /// # Examples
14    ///
15    /// ```
16    /// use musli::hint::MapHint;
17    ///
18    /// static HINT: MapHint = MapHint::with_size(16);
19    ///
20    /// assert_eq!(HINT.size, 16);
21    /// ```
22    #[inline]
23    pub const fn with_size(size: usize) -> Self {
24        Self { size }
25    }
26
27    /// Return the size hint that corresponds to this overall hint.
28    #[inline]
29    pub fn size_hint(&self) -> SizeHint {
30        SizeHint::exact(self.size)
31    }
32}