reth_db/static_file/
mask.rs

1use reth_db_api::table::Decompress;
2
3///  Trait for specifying a mask to select one column value.
4pub trait ColumnSelectorOne {
5    /// First desired column value
6    type FIRST: Decompress;
7    /// Mask to obtain desired values, should correspond to the order of columns in a `static_file`.
8    const MASK: usize;
9}
10
11///  Trait for specifying a mask to select two column values.
12pub trait ColumnSelectorTwo {
13    /// First desired column value
14    type FIRST: Decompress;
15    /// Second desired column value
16    type SECOND: Decompress;
17    /// Mask to obtain desired values, should correspond to the order of columns in a `static_file`.
18    const MASK: usize;
19}
20
21///  Trait for specifying a mask to select three column values.
22pub trait ColumnSelectorThree {
23    /// First desired column value
24    type FIRST: Decompress;
25    /// Second desired column value
26    type SECOND: Decompress;
27    /// Third desired column value
28    type THIRD: Decompress;
29    /// Mask to obtain desired values, should correspond to the order of columns in a `static_file`.
30    const MASK: usize;
31}
32
33#[macro_export]
34/// Add mask to select `N` column values from a specific static file segment row.
35macro_rules! add_static_file_mask {
36    ($(#[$attr:meta])* $mask_struct:ident $(<$generic:ident>)?, $type1:ty, $mask:expr) => {
37        $(#[$attr])*
38        #[derive(Debug)]
39        pub struct $mask_struct$(<$generic>)?$((std::marker::PhantomData<$generic>))?;
40
41        impl$(<$generic>)? ColumnSelectorOne for $mask_struct$(<$generic>)?
42        where
43            $type1: Send + Sync + std::fmt::Debug + reth_db_api::table::Decompress,
44        {
45            type FIRST = $type1;
46            const MASK: usize = $mask;
47        }
48    };
49    ($(#[$attr:meta])* $mask_struct:ident $(<$generic:ident>)?, $type1:ty, $type2:ty, $mask:expr) => {
50        $(#[$attr])*
51        #[derive(Debug)]
52        pub struct $mask_struct$(<$generic>)?$((std::marker::PhantomData<$generic>))?;
53
54        impl$(<$generic>)? ColumnSelectorTwo for $mask_struct$(<$generic>)?
55        where
56            $type1: Send + Sync + std::fmt::Debug + reth_db_api::table::Decompress,
57            $type2: Send + Sync + std::fmt::Debug + reth_db_api::table::Decompress,
58        {
59            type FIRST = $type1;
60            type SECOND = $type2;
61            const MASK: usize = $mask;
62        }
63    };
64    ($(#[$attr:meta])* $mask_struct:ident $(<$generic:ident>)?, $type1:ty, $type2:ty, $type3:ty, $mask:expr) => {
65        $(#[$attr])*
66        #[derive(Debug)]
67        pub struct $mask_struct$(<$generic>)?$((std::marker::PhantomData<$generic>))?;
68
69        impl$(<$generic>)? ColumnSelectorThree for $mask_struct$(<$generic>)?
70        where
71            $type1: Send + Sync + std::fmt::Debug + reth_db_api::table::Decompress,
72            $type2: Send + Sync + std::fmt::Debug + reth_db_api::table::Decompress,
73            $type3: Send + Sync + std::fmt::Debug + reth_db_api::table::Decompress,
74        {
75            type FIRST = $type1;
76            type SECOND = $type2;
77            type THIRD = $type3;
78            const MASK: usize = $mask;
79        }
80    };
81}