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
impl SysnoSet
sourcepub const fn new(syscalls: &[Sysno]) -> Self
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.
sourcepub const fn contains(&self, sysno: Sysno) -> bool
pub const fn contains(&self, sysno: Sysno) -> bool
Returns true if the set contains the given syscall.
sourcepub fn is_empty(&self) -> bool
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.
sourcepub fn count(&self) -> usize
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.
sourcepub fn insert(&mut self, sysno: Sysno) -> bool
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.
sourcepub fn remove(&mut self, sysno: Sysno) -> bool
pub fn remove(&mut self, sysno: Sysno) -> bool
Removes the given syscall from the set. Returns true if the syscall was in the set.
sourcepub const fn intersection(self, other: &Self) -> Self
pub const fn intersection(self, other: &Self) -> Self
Does a set intersection with this set and another.
sourcepub const fn difference(self, other: &Self) -> Self
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
.
sourcepub const fn symmetric_difference(self, other: &Self) -> Self
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.
sourcepub fn iter(&self) -> SysnoSetIter<'_> ⓘ
pub fn iter(&self) -> SysnoSetIter<'_> ⓘ
Returns an iterator that iterates over the syscalls contained in the set.
Trait Implementations§
source§impl BitOrAssign<&SysnoSet> for SysnoSet
impl BitOrAssign<&SysnoSet> for SysnoSet
source§fn bitor_assign(&mut self, rhs: &Self)
fn bitor_assign(&mut self, rhs: &Self)
|=
operation. Read moresource§impl BitOrAssign<Sysno> for SysnoSet
impl BitOrAssign<Sysno> for SysnoSet
source§fn bitor_assign(&mut self, sysno: Sysno)
fn bitor_assign(&mut self, sysno: Sysno)
|=
operation. Read moresource§impl BitOrAssign for SysnoSet
impl BitOrAssign for SysnoSet
source§fn bitor_assign(&mut self, rhs: Self)
fn bitor_assign(&mut self, rhs: Self)
|=
operation. Read moresource§impl<'de> Deserialize<'de> for SysnoSet
impl<'de> Deserialize<'de> for SysnoSet
source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
source§impl Extend<Sysno> for SysnoSet
impl Extend<Sysno> for SysnoSet
source§fn extend<T: IntoIterator<Item = Sysno>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = Sysno>>(&mut self, iter: T)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)