bobcat_features/
lib.rs

1#![no_std]
2
3pub use bobcat_storage::{const_keccak256_two_off_curve, storage_load, storage_store, U};
4
5#[macro_export]
6macro_rules! bobcat_feature {
7    ($feature_name:ident) => {
8        paste::paste! {
9            #[allow(unused)]
10            #[macro_export]
11            macro_rules! [<IF_FEATURE_ $feature_name:upper>] {
12                ($on_block:block, $off_block:block) => {
13                    if $crate::storage_load(&$crate::const_keccak256_two_off_curve(
14                        b"bobcat.features.",
15                        stringify!($feature_name).as_bytes()
16                    )).is_some() {
17                        $on_block
18                    } else {
19                        $off_block
20                    }
21                };
22            }
23
24            #[allow(unused)]
25            #[macro_export]
26            macro_rules! [<FEATURE_SET_ $feature_name:upper>] {
27                ($value:expr) => {
28                    $crate::storage_store(
29                        &$crate::const_keccak256_two_off_curve(
30                            b"bobcat.features.",
31                            stringify!($feature_name).as_bytes()
32                        ),
33                        &$crate::U::from($value)
34                    )
35                };
36            }
37        }
38    };
39}
40
41#[cfg(all(test, feature = "std"))]
42mod test {
43    bobcat_feature!(test123);
44
45    #[test]
46    fn test_feature() {
47        FEATURE_SET_TEST123!(true);
48        assert!(IF_FEATURE_TEST123!({ true }, { false }));
49    }
50}