musli_core/hint/
sequence_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 sequence.
#[non_exhaustive]
pub struct SequenceHint {
    /// The size for the sequence being encoded.
    pub size: usize,
}

impl SequenceHint {
    /// Create a new sequence hint with the specified size.
    ///
    /// # Examples
    ///
    /// ```
    /// use musli::hint::SequenceHint;
    ///
    /// static HINT: SequenceHint = SequenceHint::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)
    }
}