pub struct CpuSet { /* private fields */ }Expand description
A sorted, deduplicated, non-empty set of logical CPUs.
§Examples
use tenferro_cpu::{CpuId, CpuSet};
let cpus = CpuSet::new([CpuId::new(3), CpuId::new(1), CpuId::new(3)])?;
assert_eq!(cpus.as_usize_vec(), vec![1, 3]);Implementations§
Source§impl CpuSet
impl CpuSet
Sourcepub fn new(cpus: impl IntoIterator<Item = CpuId>) -> Result<Self, CpuSetError>
pub fn new(cpus: impl IntoIterator<Item = CpuId>) -> Result<Self, CpuSetError>
Construct a sorted and deduplicated CPU set.
§Examples
use tenferro_cpu::{CpuId, CpuSet};
let cpus = CpuSet::new([CpuId::new(2), CpuId::new(0)])?;
assert_eq!(cpus.as_usize_vec(), vec![0, 2]);§Errors
Returns CpuSetError::Empty when the iterator yields no CPUs.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Return the number of logical CPUs in this set.
§Examples
use tenferro_cpu::{CpuId, CpuSet};
assert_eq!(CpuSet::new([CpuId::new(0), CpuId::new(1)])?.len(), 2);Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Report whether this set is empty.
A successfully constructed CpuSet is never empty.
§Examples
use tenferro_cpu::{CpuId, CpuSet};
assert!(!CpuSet::new([CpuId::new(0)])?.is_empty());Sourcepub fn as_slice(&self) -> &[CpuId]
pub fn as_slice(&self) -> &[CpuId]
Return the sorted logical CPU identifiers.
§Examples
use tenferro_cpu::{CpuId, CpuSet};
let cpus = CpuSet::new([CpuId::new(4), CpuId::new(2)])?;
assert_eq!(cpus.as_slice(), &[CpuId::new(2), CpuId::new(4)]);Sourcepub fn as_usize_vec(&self) -> Vec<usize>
pub fn as_usize_vec(&self) -> Vec<usize>
Copy the sorted logical CPU numbers into a vector.
§Examples
use tenferro_cpu::{CpuId, CpuSet};
let cpus = CpuSet::new([CpuId::new(6), CpuId::new(5)])?;
assert_eq!(cpus.as_usize_vec(), vec![5, 6]);Trait Implementations§
impl Eq for CpuSet
impl StructuralPartialEq for CpuSet
Auto Trait Implementations§
impl Freeze for CpuSet
impl RefUnwindSafe for CpuSet
impl Send for CpuSet
impl Sync for CpuSet
impl Unpin for CpuSet
impl UnsafeUnpin for CpuSet
impl UnwindSafe for CpuSet
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more