Skip to main content

bast3st_eval/evaluation/
features.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash, Default)]
4pub struct Features(u32);
5
6impl std::fmt::Debug for Features {
7    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
8        bitflags::parser::to_writer(self, f)
9    }
10}
11
12impl Serialize for Features {
13    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
14    where
15        S: serde::Serializer,
16    {
17        bitflags::serde::serialize(self, serializer)
18    }
19}
20
21impl<'de> Deserialize<'de> for Features {
22    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
23    where
24        D: serde::Deserializer<'de>,
25    {
26        bitflags::serde::deserialize(deserializer)
27    }
28}
29
30bitflags::bitflags! {
31    impl Features : u32 {
32        /// Allow access to INPUT, OUTPUT, RANDOMS, LISTS, ...
33        const READ_RUNDATA = 1 << 0;
34        /// End a current test (available in test hooks and tests)
35        const END_THIS_TEST = 1 << 1;
36        /// Send global message (available if message sending is allowed)
37        const SENDMSG_SPEC = 1 << 2;
38        /// Send message to category (available in category and its tests)
39        const SENDMSG_CATEGORY = 1 << 3;
40        /// Send message to the maintest level (only in main- and alternative test)
41        const SENDMSG_MAINTEST = 1 << 4;
42        /// Send message to the current entity level
43        const SENDMSG_CURRENT = 1 << 5;
44
45        const PermittedFEAT_SpecHook = Self::SENDMSG_SPEC.0 | Self::SENDMSG_CURRENT.0;
46        const PermittedFEAT_CategoryHook =
47              Self::SENDMSG_SPEC.0
48            | Self::SENDMSG_CATEGORY.0
49            | Self::SENDMSG_CURRENT.0;
50
51        const PermittedFEAT_PreTestHook =
52              Self::END_THIS_TEST.0
53            | Self::SENDMSG_SPEC.0
54            | Self::SENDMSG_CATEGORY.0
55            | Self::SENDMSG_MAINTEST.0
56            | Self::SENDMSG_CURRENT.0;
57        const PermittedFEAT_TestScope =
58              Self::PermittedFEAT_PreTestHook.0
59            | Self::READ_RUNDATA.0;
60        const PermittedFEAT_PassTestCrit = Self::PermittedFEAT_TestScope.0;
61        const PermittedFEAT_PostTestHook = Self::PermittedFEAT_TestScope.0;
62    }
63}
64
65pub trait RequiredFeatures {
66    fn required_features(&self) -> Features;
67}