local-ip-address
local-ip-address copied to clipboard
failed to resolve: use of undeclared crate or module `env`
System : macOS
error[E0433]: failed to resolve: use of undeclared crate or module `env`
--> /Users/swithun/.cargo/registry/src/github.com-1ecc6299db9ec823/local-ip-address-0.5.1/src/lib.rs:179:41
|
179 | Err(Error::PlatformNotSupported(env::consts::OS.to_string()))
| ^^^ use of undeclared crate or module `env`
error[E0433]: failed to resolve: use of undeclared crate or module `env`
--> /Users/swithun/.cargo/registry/src/github.com-1ecc6299db9ec823/local-ip-address-0.5.1/src/lib.rs:194:37
|
194 | Err(Error::PlatformNotSupported(env::consts::OS.to_string()))
| ^^^ use of undeclared crate or module `env`
For more information about this error, try `rustc --explain E0433`.
error: could not compile `local-ip-address` due to 2 previous errors
Should be fixed with https://github.com/EstebanBorai/local-ip-address/pull/108/commits/63652700de463c25cea00800eb38d3343310a2dd
Hi @swithun-liu, thanks for opening this issue.
Im testing local-ip-address
using macOS as well with the same version 0.5.1
.
➜ test-local-ip-address git:(master) ✗ cargo run
Blocking waiting for file lock on build directory
Compiling libc v0.2.140
Compiling thiserror v1.0.39
Compiling local-ip-address v0.5.1
Compiling test-local-ip-address v0.1.0 (/Users/esteban/Desktop/test-local-ip-address)
Finished dev [unoptimized + debuginfo] target(s) in 4.28s
Running `target/debug/test-local-ip-address`
Local IP: 192.168.8.104
Got 12 interfaces
IF: lo0, IP: 127.0.0.1
IF: lo0, IP: ::1
IF: lo0, IP: fe80::1
IF: anpi2, IP: fe80::44dd:3dff:fecf:ce37
IF: anpi1, IP: fe80::44dd:3dff:fecf:ce36
IF: anpi0, IP: fe80::44dd:3dff:fecf:ce35
IF: en0, IP: fe80::ca3:bf2b:686d:3ef6
IF: en0, IP: 192.168.8.104
IF: awdl0, IP: fe80::74a5:cbff:fe51:fda6
IF: llw0, IP: fe80::74a5:cbff:fe51:fda6
IF: utun0, IP: fe80::fc64:5350:be7d:d7dd
IF: utun1, IP: fe80::5b6c:784d:46a1:435e
This is the code:
use local_ip_address::{list_afinet_netifas, local_ip};
fn main() {
match local_ip() {
Ok(ip) => println!("Local IP: {}", ip),
Err(err) => println!("Failed to get local IP: {}", err),
};
match list_afinet_netifas() {
Ok(netifs) => {
println!("Got {} interfaces", netifs.len());
for netif in netifs {
println!("IF: {}, IP: {}", netif.0, netif.1);
}
}
Err(err) => println!("Failed to get list of network interfaces: {}", err),
};
}
It would be nice to have more details on how you are running this in order to reproduce, thanks!