use crate::net::DriverKind;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Workers {
pub(crate) kind: DriverKind,
pub(crate) count: Option<u16>,
}
pub(crate) const BLOCKING_DEFAULT: u16 = 256;
impl Workers {
#[must_use]
pub fn auto() -> Self {
Workers {
kind: DriverKind::Auto,
count: None,
}
}
#[must_use]
pub fn blocking(threads: u16) -> Self {
Workers {
kind: DriverKind::Blocking,
count: Some(threads),
}
}
#[must_use]
pub fn kind(&self) -> DriverKind {
self.kind
}
#[must_use]
pub fn count(&self) -> Option<u16> {
self.count
}
pub(crate) fn blocking_threads(&self) -> u16 {
self.count.unwrap_or(BLOCKING_DEFAULT)
}
}
impl Default for Workers {
fn default() -> Self {
Workers::auto()
}
}