#[derive(Copy, Clone, Debug)]
pub struct SpaceConfig {
width: u32,
count: Option<u32>,
}
impl SpaceConfig {
pub const fn new(width: u32, count: Option<u32>) -> Self {
Self { width, count }
}
pub fn peek_next_width(&self, n: u32) -> u32 {
match self.count {
None => n * self.width,
Some(count) => n * self.width + count.min(n),
}
}
pub fn consume(&mut self, n: u32) -> u32 {
let w = self.peek_next_width(n);
if let Some(count) = self.count.as_mut() {
*count = count.saturating_sub(n);
}
w
}
}