use core::fmt::{self, Write as _};
use core::str::FromStr;
use arrayvec::ArrayString;
use itoa::{Buffer, Integer};
use powerfmt::ext::FormatterExt as _;
const LONGEST_COUNT: usize = "-9223372036854775808 ticks".len();
#[inline]
pub(crate) fn pad(formatter: &mut fmt::Formatter<'_>, text: &str) -> fmt::Result {
if formatter.width().is_none() {
return formatter.write_str(text);
}
formatter.pad_with_width(text.len(), format_args!("{text}"))
}
pub(crate) struct Count<I>(pub(crate) I, pub(crate) &'static str);
impl<I: Integer> fmt::Display for Count<I> {
#[inline]
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut text = ArrayString::<LONGEST_COUNT>::new();
text.write_str(Buffer::new().format(self.0))?;
text.write_str(self.1)?;
pad(formatter, &text)
}
}
#[inline]
pub(crate) fn read_count<T: FromStr>(text: &str) -> Option<T> {
if text.starts_with('+') { None } else { text.parse().ok() }
}