use crate::{
InputOutputLimit,
LogOutputLimitError,
};
pub(crate) const TRUNCATION_MARKER: &str = "<truncated>";
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
#[must_use = "use the validated limit to bound redacted display output"]
pub struct LogOutputLimit {
max_bytes: usize,
}
impl LogOutputLimit {
pub const MINIMUM: usize = TRUNCATION_MARKER.len();
#[inline]
pub const fn new(max_bytes: usize) -> Result<Self, LogOutputLimitError> {
if max_bytes < Self::MINIMUM {
Err(LogOutputLimitError::new(max_bytes))
} else {
Ok(Self { max_bytes })
}
}
#[inline(always)]
pub const fn max_bytes(self) -> usize {
self.max_bytes
}
}
impl From<InputOutputLimit> for LogOutputLimit {
#[inline(always)]
fn from(budget: InputOutputLimit) -> Self {
Self {
max_bytes: budget.max_output_bytes(),
}
}
}