#[inline]
#[must_use]
pub(crate) fn strip_ip_prefix(ip: &str) -> &str {
const PREFIX: &str = "::ffff:";
if ip.as_bytes().first() != Some(&b':') {
return ip;
}
if ip.len() > PREFIX.len() && ip[..PREFIX.len()].eq_ignore_ascii_case(PREFIX) {
&ip[PREFIX.len()..]
} else {
ip
}
}
#[inline]
#[must_use]
pub(crate) fn f32_ms_to_i64(ms: f32) -> i64 {
if !ms.is_finite() {
return 0;
}
const MAX_I64_F64: f64 = 9_223_372_036_854_775_807.0; const MIN_I64_F64: f64 = -9_223_372_036_854_775_808.0;
let ms_f64 = f64::from(ms);
if ms_f64 > MAX_I64_F64 {
i64::MAX
} else if ms_f64 < MIN_I64_F64 {
i64::MIN
} else {
let clamped = ms_f64.round();
#[expect(
clippy::cast_possible_truncation,
reason = "value is clamped to i64 range above; saturating cast (Rust 1.45+) handles boundary values correctly"
)]
{
clamped as i64
}
}
}
pub(crate) fn ensure_parent_dir(path: &std::path::Path) -> std::io::Result<()> {
if let Some(parent) = path.parent().filter(|p| !p.exists()) {
std::fs::create_dir_all(parent)?;
}
Ok(())
}