From 45e74a61bb5ebe689e560ad4d40ac9d238d26f9f Mon Sep 17 00:00:00 2001 From: messense Date: Tue, 28 Feb 2023 13:18:40 +0800 Subject: [PATCH] Rename `idx` to `index` --- src/lib.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 58d2718..f5bf878 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,7 +24,7 @@ pub struct Interface { /// The address details of the interface. pub addr: IfAddr, /// The index of the interface. - pub idx: Option, + pub index: Option, } impl Interface { @@ -192,19 +192,19 @@ mod getifaddrs_posix { let name = unsafe { CStr::from_ptr(ifaddr.ifa_name) } .to_string_lossy() .into_owned(); - let idx = { - let idx = unsafe { if_nametoindex(ifaddr.ifa_name) }; + let index = { + let index = unsafe { if_nametoindex(ifaddr.ifa_name) }; // From `man if_nametoindex 3`: // The if_nametoindex() function maps the interface name specified in ifname to its // corresponding index. If the specified interface does not exist, it returns 0. - if idx == 0 { + if index == 0 { None } else { - Some(idx) + Some(index) } }; - ret.push(Interface { name, addr, idx }); + ret.push(Interface { name, addr, index }); } Ok(ret) @@ -340,7 +340,7 @@ mod getifaddrs_windows { ret.push(Interface { name: ifaddr.name(), addr, - idx: ifaddr.index(), + index: ifaddr.index(), }); } } @@ -454,7 +454,7 @@ mod tests { ); // if index is set, it is non-zero for interface in &ifaces { - if let Some(idx) = interface.idx { + if let Some(idx) = interface.index { assert!(idx > 0); } } @@ -476,7 +476,7 @@ mod tests { } #[cfg(not(windows))] - assert!(interface.idx.is_some()); + assert!(interface.index.is_some()); } assert!(listed); }