Skip to main content

CapabilitySet

Struct CapabilitySet 

Source
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

Source

pub const BYTES: usize = 32

How many bytes of bitset this build carries.

Source

pub const MAX_BIT: u16 = 255

The highest capability bit this build can represent.

Source

pub const fn new() -> Self

An empty set.

Source

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.

Source

pub const fn contains(self, cap: Capability) -> bool

Whether the set contains a capability.

Source

pub fn is_empty(self) -> bool

Whether the set is empty as far as this build can tell.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn intersection(self, other: Self) -> Self

The capabilities in both sets.

Source

pub fn union(self, other: Self) -> Self

The capabilities in either set.

Source

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

Source§

fn clone(&self) -> CapabilitySet

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for CapabilitySet

Source§

impl Debug for CapabilitySet

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CapabilitySet

Source§

fn default() -> CapabilitySet

Returns the “default value” for a type. Read more
Source§

impl Eq for CapabilitySet

Source§

impl PartialEq for CapabilitySet

Source§

fn eq(&self, other: &CapabilitySet) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for CapabilitySet

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.