abi_stable/prefix_type/
accessible_fields.rs

1use crate::sabi_types::bitarray::{bool_to_enum, enum_to_bool, BitArray64, BooleanEnum};
2
3////////////////////////////////////////////////////////////////////////////////
4
5/// Whether a field is accessible.
6#[derive(StableAbi, Debug, Copy, Clone, PartialEq, Eq)]
7#[repr(u8)]
8pub enum IsAccessible {
9    ///
10    No = 0,
11    ///
12    Yes = 1,
13}
14
15impl IsAccessible {
16    /// Constructs an IsAccessible with a bool saying whether this is accessible.
17    pub const fn new(is_accessible: bool) -> Self {
18        bool_to_enum(is_accessible)
19    }
20    /// Describes whether this is accessible.
21    pub const fn is_accessible(self) -> bool {
22        enum_to_bool(self)
23    }
24}
25
26unsafe impl BooleanEnum for IsAccessible {
27    const FALSE: Self = Self::No;
28    const TRUE: Self = Self::Yes;
29}
30
31/// An array with whether the ith field of a prefix-type
32/// is accessible through its accessor method.
33pub type FieldAccessibility = BitArray64<IsAccessible>;
34
35////////////////////////////////////////////////////////////////////////////////
36
37/// Whether a field is conditional,
38/// whether it has a `#[sabi(accessible_if = expression)]` helper attribute or not.
39#[derive(StableAbi, Debug, Copy, Clone, PartialEq, Eq)]
40#[repr(u8)]
41pub enum IsConditional {
42    ///
43    No = 0,
44    ///
45    Yes = 1,
46}
47
48impl IsConditional {
49    /// Constructs an IsConditional with a bool saying this is conditional.
50    pub const fn new(is_conditional: bool) -> Self {
51        bool_to_enum(is_conditional)
52    }
53    /// Describes whether this is conditional.
54    pub const fn is_conditional(self) -> bool {
55        enum_to_bool(self)
56    }
57}
58
59unsafe impl BooleanEnum for IsConditional {
60    const FALSE: Self = Self::No;
61    const TRUE: Self = Self::Yes;
62}
63
64/// An array with whether the ith field in the prefix of a prefix-type
65/// is conditional,which means whether it has the
66/// `#[sabi(accessible_if = expression)]` attribute applied to it.
67pub type FieldConditionality = BitArray64<IsConditional>;