musli_core/hint/
sequence_hint.rs

1use crate::de::SizeHint;
2
3/// A hint passed in when encoding a sequence.
4#[non_exhaustive]
5pub struct SequenceHint {
6    /// The size for the sequence being encoded.
7    pub size: usize,
8}
9
10impl SequenceHint {
11    /// Create a new sequence hint with the specified size.
12    ///
13    /// # Examples
14    ///
15    /// ```
16    /// use musli::hint::SequenceHint;
17    ///
18    /// static HINT: SequenceHint = SequenceHint::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}