#[derive(Debug, Clone, Eq, PartialEq)]
pub struct RestartIntervalPolicy(Vec<u8>);
impl std::ops::Deref for RestartIntervalPolicy {
type Target = [u8];
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl RestartIntervalPolicy {
pub(crate) fn get(&self, level: usize) -> u8 {
#[expect(clippy::expect_used, reason = "policy is expected not to be empty")]
self.0
.get(level)
.copied()
.unwrap_or_else(|| self.last().copied().expect("policy should not be empty"))
}
#[must_use]
pub fn all(c: u8) -> Self {
Self(vec![c])
}
#[must_use]
pub fn new(policy: impl Into<Vec<u8>>) -> Self {
let policy = policy.into();
assert!(
!policy.is_empty(),
"restart interval policy may not be empty"
);
assert!(policy.len() <= 255, "restart interval policy is too large");
Self(policy)
}
}