use std::time::Duration;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct OutputLimits {
pub(crate) max_stdout_bytes: usize,
pub(crate) max_stderr_bytes: usize,
}
impl OutputLimits {
pub const DEFAULT_STDOUT_BYTES: usize = 32 * 1024 * 1024;
pub const DEFAULT_STDERR_BYTES: usize = 1024 * 1024;
#[must_use]
pub const fn max_stdout_bytes(self, bytes: usize) -> Self {
Self {
max_stdout_bytes: bytes,
..self
}
}
#[must_use]
pub const fn max_stderr_bytes(self, bytes: usize) -> Self {
Self {
max_stderr_bytes: bytes,
..self
}
}
#[must_use]
pub const fn stdout_bytes(self) -> usize {
self.max_stdout_bytes
}
#[must_use]
pub const fn stderr_bytes(self) -> usize {
self.max_stderr_bytes
}
}
impl Default for OutputLimits {
fn default() -> Self {
Self {
max_stdout_bytes: Self::DEFAULT_STDOUT_BYTES,
max_stderr_bytes: Self::DEFAULT_STDERR_BYTES,
}
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct DispatchLimits {
pub(crate) max_in_flight: usize,
pub(crate) acquire_timeout: Option<Duration>,
}
impl DispatchLimits {
pub const DEFAULT_IN_FLIGHT: usize = 16;
#[must_use]
pub const fn max_in_flight(self, permits: usize) -> Self {
Self {
max_in_flight: if permits == 0 { 1 } else { permits },
..self
}
}
#[must_use]
pub const fn acquire_timeout(self, timeout: Option<Duration>) -> Self {
Self {
acquire_timeout: timeout,
..self
}
}
#[must_use]
pub const fn in_flight(self) -> usize {
self.max_in_flight
}
}
impl Default for DispatchLimits {
fn default() -> Self {
Self {
max_in_flight: Self::DEFAULT_IN_FLIGHT,
acquire_timeout: None,
}
}
}
#[cfg(feature = "control-mode")]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct ControlLimits {
pub(crate) max_line_bytes: usize,
pub(crate) max_block_bytes: usize,
}
#[cfg(feature = "control-mode")]
impl ControlLimits {
pub const DEFAULT_LINE_BYTES: usize = 8 * 1024 * 1024;
pub const DEFAULT_BLOCK_BYTES: usize = 64 * 1024 * 1024;
#[must_use]
pub const fn max_line_bytes(self, bytes: usize) -> Self {
Self {
max_line_bytes: bytes,
..self
}
}
#[must_use]
pub const fn max_block_bytes(self, bytes: usize) -> Self {
Self {
max_block_bytes: bytes,
..self
}
}
#[must_use]
pub const fn line_bytes(self) -> usize {
self.max_line_bytes
}
#[must_use]
pub const fn block_bytes(self) -> usize {
self.max_block_bytes
}
}
#[cfg(feature = "control-mode")]
impl Default for ControlLimits {
fn default() -> Self {
Self {
max_line_bytes: Self::DEFAULT_LINE_BYTES,
max_block_bytes: Self::DEFAULT_BLOCK_BYTES,
}
}
}