bitcode/derive/
empty.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
33
34
35
36
37
38
39
use crate::coder::{Buffer, Decoder, Encoder, Result, View};
use alloc::vec::Vec;
use core::marker::PhantomData;
use core::num::NonZeroUsize;

#[derive(Default)]
pub struct EmptyCoder;

impl<T> Encoder<PhantomData<T>> for EmptyCoder {
    fn encode(&mut self, _: &PhantomData<T>) {}
}

impl Buffer for EmptyCoder {
    fn collect_into(&mut self, _: &mut Vec<u8>) {}
    fn reserve(&mut self, _: NonZeroUsize) {}
}

impl<'a> View<'a> for EmptyCoder {
    fn populate(&mut self, _: &mut &'a [u8], _: usize) -> Result<()> {
        Ok(())
    }
}

impl<'a, T> Decoder<'a, PhantomData<T>> for EmptyCoder {
    fn decode(&mut self) -> PhantomData<T> {
        PhantomData
    }
}

#[cfg(test)]
mod tests {
    use alloc::vec::Vec;
    use core::marker::PhantomData;

    fn bench_data() -> Vec<PhantomData<()>> {
        vec![PhantomData; 100]
    }
    crate::bench_encode_decode!(phantom_data_vec: Vec<_>);
}