use super::funejson::Value; use super::net_ipv4_format_ipv4::format_ipv4; /// The dotted-quad mask for a prefix length: 24 is 255.255.255.0. /// /// # Panics /// Panics when the prefix is outside 0 to 32. pub fn prefix_to_netmask(prefix: i64) -> String { if !(0..=32).contains(&prefix) { panic!("prefix must be an integer from 0 to 32, received {}", prefix); } format_ipv4(4294967296 - (1i64 << (32 - prefix))) } pub fn fune_vector(args: &[Value]) -> Value { let prefix = match &args[0] { Value::Int(i) => *i, other => panic!("prefix must be an integer from 0 to 32, received {}", other), }; Value::str(&prefix_to_netmask(prefix)) }