Struct syscalls::SysnoSet

source ·
pub struct SysnoSet { /* private fields */ }
Expand description

A set of syscalls.

This provides constant-time lookup of syscalls within a bitset.

§Examples

let syscalls = SysnoSet::new(&[Sysno::read, Sysno::write, Sysno::openat, Sysno::close]);
assert!(syscalls.contains(Sysno::read));
assert!(syscalls.contains(Sysno::close));

Most operations can be done at compile-time as well.

const SYSCALLS: SysnoSet =
    SysnoSet::new(&[Sysno::read, Sysno::write, Sysno::close])
        .union(&SysnoSet::new(&[Sysno::openat]));
const _: () = assert!(SYSCALLS.contains(Sysno::read));
const _: () = assert!(SYSCALLS.contains(Sysno::openat));

Implementations§

source§

impl SysnoSet

source

pub const fn new(syscalls: &[Sysno]) -> Self

Initialize the syscall set with the given slice of syscalls.

Since this is a const fn, this can be used at compile-time.

source

pub const fn empty() -> Self

Creates an empty set of syscalls.

source

pub const fn all() -> Self

Creates a set containing all valid syscalls.

source

pub const fn contains(&self, sysno: Sysno) -> bool

Returns true if the set contains the given syscall.

source

pub fn is_empty(&self) -> bool

Returns true if the set is empty. Although this is an O(1) operation (because the total number of possible syscalls is always constant), it must go through the whole bit set to count the number of bits. Thus, this may have a large, constant overhead.

source

pub fn clear(&mut self)

Clears the set, removing all syscalls.

source

pub fn count(&self) -> usize

Returns the number of syscalls in the set. Although this is an O(1) operation (because the total number of syscalls is always constant), it must go through the whole bit set to count the number of bits. Thus, this may have a large, constant overhead.

source

pub fn insert(&mut self, sysno: Sysno) -> bool

Inserts the given syscall into the set. Returns true if the syscall was not already in the set.

source

pub fn remove(&mut self, sysno: Sysno) -> bool

Removes the given syscall from the set. Returns true if the syscall was in the set.

source

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

Does a set union with this set and another.

source

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

Does a set intersection with this set and another.

source

pub const fn difference(self, other: &Self) -> Self

Calculates the difference with this set and another. That is, the resulting set only includes the syscalls that are in self but not in other.

source

pub const fn symmetric_difference(self, other: &Self) -> Self

Calculates the symmetric difference with this set and another. That is, the resulting set only includes the syscalls that are in self or in other, but not in both.

source

pub fn iter(&self) -> SysnoSetIter<'_>

Returns an iterator that iterates over the syscalls contained in the set.

Trait Implementations§

source§

impl BitOr for SysnoSet

§

type Output = SysnoSet

The resulting type after applying the | operator.
source§

fn bitor(self, rhs: Self) -> Self::Output

Performs the | operation. Read more
source§

impl BitOrAssign<&SysnoSet> for SysnoSet

source§

fn bitor_assign(&mut self, rhs: &Self)

Performs the |= operation. Read more
source§

impl BitOrAssign<Sysno> for SysnoSet

source§

fn bitor_assign(&mut self, sysno: Sysno)

Performs the |= operation. Read more
source§

impl BitOrAssign for SysnoSet

source§

fn bitor_assign(&mut self, rhs: Self)

Performs the |= operation. Read more
source§

impl Clone for SysnoSet

source§

fn clone(&self) -> SysnoSet

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for SysnoSet

source§

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

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

impl Default for SysnoSet

source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for SysnoSet

source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Extend<Sysno> for SysnoSet

source§

fn extend<T: IntoIterator<Item = Sysno>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl FromIterator<Sysno> for SysnoSet

source§

fn from_iter<I: IntoIterator<Item = Sysno>>(iter: I) -> Self

Creates a value from an iterator. Read more
source§

impl<'a> IntoIterator for &'a SysnoSet

§

type Item = Sysno

The type of the elements being iterated over.
§

type IntoIter = SysnoSetIter<'a>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl PartialEq for SysnoSet

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for SysnoSet

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Eq for SysnoSet

source§

impl StructuralPartialEq for SysnoSet

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> 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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,