#[derive(Debug, Clone)]
pub struct RecommendedConcurrency {
range: std::ops::Range<usize>,
}
impl RecommendedConcurrency {
#[must_use]
pub fn new(range: impl std::ops::RangeBounds<usize>) -> Self {
let start = match range.start_bound() {
std::ops::Bound::Included(start) => *start,
std::ops::Bound::Excluded(start) => start.saturating_add(1),
std::ops::Bound::Unbounded => 0,
};
let end = match range.end_bound() {
std::ops::Bound::Excluded(end) => *end,
std::ops::Bound::Included(end) => end.saturating_add(1),
std::ops::Bound::Unbounded => usize::MAX,
};
Self {
range: start.max(1)..end.max(1),
}
}
#[must_use]
pub fn new_minimum(minimum: usize) -> Self {
Self::new(minimum..)
}
#[must_use]
pub fn new_maximum(maximum: usize) -> Self {
Self::new(..maximum)
}
#[must_use]
pub fn min(&self) -> usize {
self.range.start
}
#[must_use]
pub fn max(&self) -> usize {
self.range.end
}
}