pub struct CapabilitySet { /* private fields */ }Expand description
A set of capabilities.
The set is a fixed 32 bytes, so it holds 256 capabilities and needs no allocation. On the wire
it is a variable-length byte string, so a future version can make it wider without breaking
anything, and CapabilitySet::has_bits_beyond_this_build is how this version notices that
happened instead of silently ignoring the extra bits.
Implementations§
Source§impl CapabilitySet
impl CapabilitySet
Sourcepub const fn with(self, cap: Capability) -> Self
pub const fn with(self, cap: Capability) -> Self
Adds a capability and returns the set, so sets can be built in one expression.
A capability above CapabilitySet::MAX_BIT cannot be represented by this build and is
ignored. That cannot happen by accident, because every capability this build knows about is
a constant in this file.
Sourcepub const fn contains(self, cap: Capability) -> bool
pub const fn contains(self, cap: Capability) -> bool
Whether the set contains a capability.
Sourcepub const fn has_bits_beyond_this_build(self) -> bool
pub const fn has_bits_beyond_this_build(self) -> bool
Whether the bytes this set was decoded from had bits set past what this build can hold.
This matters on the required side. A decoder built against a later version of the ABI may require a capability that did not exist when this host was compiled, and a host that just truncated the bitset would conclude the decoder required nothing and run it anyway. That is the failure this flag exists to prevent.
Sourcepub fn from_bytes(bytes: &[u8]) -> Self
pub fn from_bytes(bytes: &[u8]) -> Self
Reads a set from its wire form.
Bytes past what this build can hold are not stored, but if any of them are non-zero the set remembers that.
Sourcepub fn as_bytes(&self) -> &[u8]
pub fn as_bytes(&self) -> &[u8]
The wire form, with trailing zero bytes trimmed off so an empty set costs nothing.
Trimming is safe because a reader treats a missing byte as zero, which is what
CapabilitySet::from_bytes does.
Sourcepub fn difference(self, other: Self) -> Self
pub fn difference(self, other: Self) -> Self
The capabilities in this set that are not in other.
The beyond flag rides along, because a bit this build cannot name is by definition a bit
other does not offer.
Sourcepub fn intersection(self, other: Self) -> Self
pub fn intersection(self, other: Self) -> Self
The capabilities in both sets.
Sourcepub fn iter(&self) -> impl Iterator<Item = Capability> + '_
pub fn iter(&self) -> impl Iterator<Item = Capability> + '_
Every capability in the set, lowest bit first.
Bits past CapabilitySet::MAX_BIT cannot be listed, which is what
CapabilitySet::has_bits_beyond_this_build is for.
Trait Implementations§
Source§impl Clone for CapabilitySet
impl Clone for CapabilitySet
Source§fn clone(&self) -> CapabilitySet
fn clone(&self) -> CapabilitySet
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more