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
40
41
42
43
44
//! Capability flags for inspectable values.
/// Capabilities that an inspectable value supports.
///
/// This allows consumers to discover what operations are available
/// without attempting them and failing.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct Capability {
bits: u32,
}
impl Capability {
/// No capabilities.
pub const NONE: Self = Self { bits: 0 };
/// Value can be inspected (always true for Inspect implementations).
pub const INSPECT: Self = Self { bits: 1 << 0 };
/// Value has children that can be traversed.
pub const CHILDREN: Self = Self { bits: 1 << 1 };
/// Value supports field/index access.
pub const ACCESS: Self = Self { bits: 1 << 2 };
/// All read capabilities.
pub const READ_ALL: Self =
Self { bits: Self::INSPECT.bits | Self::CHILDREN.bits | Self::ACCESS.bits };
/// Check if this capability set contains another.
pub fn contains(self, other: Self) -> bool {
(self.bits & other.bits) == other.bits
}
/// Combine two capability sets.
pub fn union(self, other: Self) -> Self {
Self { bits: self.bits | other.bits }
}
}
impl Default for Capability {
fn default() -> Self {
Self::INSPECT
}
}