binbin/
deferred.rs

1/// A placeholder for a value that we'll learn only later in our process of
2/// writing out data.
3#[derive(Copy, Clone)]
4pub struct Deferred<'a, T> {
5    pub(crate) idx: usize,
6    pub(crate) initial: T,
7    _phantom: std::marker::PhantomData<&'a T>,
8}
9
10impl<'a, T> Deferred<'a, T> {
11    pub(crate) fn new(idx: usize, initial: T) -> Self {
12        Self {
13            idx: idx,
14            initial: initial,
15            _phantom: std::marker::PhantomData,
16        }
17    }
18}
19
20impl<'a, T> Deferred<'a, T>
21where
22    T: crate::pack::IntoPack,
23    <T as crate::pack::IntoPack>::PackType: crate::pack::FixedLenPack,
24{
25    /// The size, in bytes, that the deferred value will take up when written.
26    pub const PACK_LEN: usize =
27        <<T as crate::pack::IntoPack>::PackType as crate::pack::FixedLenPack>::PACK_LEN;
28
29    /// Returns the size, in bytes, that the deferred value will take up when
30    /// written.
31    pub fn pack_len(&mut self) -> usize {
32        Self::PACK_LEN
33    }
34}