changed ip_to_string's argument from u32 to &u32

This commit is contained in:
asxalex 2024-04-01 17:00:52 +08:00
parent dd08d4e6d0
commit b5f21063ad
2 changed files with 5 additions and 5 deletions

View File

@ -120,7 +120,7 @@ pub fn is_multi_broadcast(ip: u32) -> bool {
first >= 224 && first <= 239
}
pub fn ip_to_string(ip: u32) -> String {
pub fn ip_to_string(ip: &u32) -> String {
format!(
"{}.{}.{}.{}",
((ip >> 24) & 0xff) as u8,

View File

@ -147,9 +147,9 @@ mod tests {
#[test]
fn test_net_bit_to_ip() {
assert_eq!(ip_to_string(net_bit_len_to_mask(8)), "255.0.0.0");
assert_eq!(ip_to_string(net_bit_len_to_mask(16)), "255.255.0.0");
assert_eq!(ip_to_string(net_bit_len_to_mask(24)), "255.255.255.0");
assert_eq!(ip_to_string(net_bit_len_to_mask(32)), "255.255.255.255");
assert_eq!(ip_to_string(&net_bit_len_to_mask(8)), "255.0.0.0");
assert_eq!(ip_to_string(&net_bit_len_to_mask(16)), "255.255.0.0");
assert_eq!(ip_to_string(&net_bit_len_to_mask(24)), "255.255.255.0");
assert_eq!(ip_to_string(&net_bit_len_to_mask(32)), "255.255.255.255");
}
}