This example fails to compile:
extern crate nix;
use std::os::unix::io::RawFd;
fn func(fd: RawFd, buf: &mut [u8]) -> Result<(), nix::Error> {
let (size, nix_addr) = nix::sys::socket::recvfrom(
fd, buf
)?;
let addr = match nix_addr {
//nix::sys::socket::SockAddr::Inet(addr) => addr.to_std(),
Inet(addr) => addr.to_std(),
_ => panic!(),
};
Ok(())
}
fn main() {}
The error, in this version is:
error[E0531]: unresolved tuple struct/variant `Inet`
--> match_arms.rs:14:3
|
14 | Inet(addr) => addr.to_std(),
| ^^^^
Swapping the Inet
line for the commented out one successfully compiles.
The compiler seems to be requiring me to specify the enum type itself, I suppose so that it knows that the variant I'm specifying in the match
arm is legit. But why? Can't the enum be inferred? Doesn't the compiler have enough information here to realize that nix_addr
is a nix::…::SocketAddr
, and thus, that Inet
is a valid variant (and one with data)?
Why do I have to type the whole thing out, or drag the name into the current scope with a use
?
I also tried _::Inet
, which also failed.