use super::funejson::Value; /// Dotted-quad text for an unsigned 32-bit address: the inverse of parse_ipv4. /// /// # Panics /// Panics when the value is outside 0 to 4294967295. pub fn format_ipv4(value: i64) -> String { if !(0..=4294967295).contains(&value) { panic!("IPv4 value must be an integer from 0 to 4294967295, received {}", value); } format!( "{}.{}.{}.{}", (value >> 24) & 255, (value >> 16) & 255, (value >> 8) & 255, value & 255 ) } pub fn fune_vector(args: &[Value]) -> Value { // A fractional number cannot become an i64 without changing it, so refuse // it with the wording TypeScript and Python use. let value = match &args[0] { Value::Int(i) => *i, other => panic!("IPv4 value must be an integer from 0 to 4294967295, received {}", other), }; Value::str(&format_ipv4(value)) }