I need to do a bunch of platform specific imports, and didn't want to have to annotate each and every use
statement with a #[cfg()]
directive. So I came up with this:
#[cfg(windows)]
mod _plat_specifics {
pub use winapi::SOCKADDR as sockaddr;
pub use winapi::SOCKADDR_IN as sockaddr_in;
pub use winapi::IN_ADDR as in_addr;
pub use winapi::{AF_INET, AF_INET6};
pub use winapi::{SOCK_STREAM, SOCK_DGRAM};
}
#[cfg(not(windows))]
mod _plat_specifics {
pub use libc::{sockaddr, sockaddr_in, in_addr};
pub use libc::{AF_INET, AF_INET6};
pub use libc::{SOCK_STREAM, SOCK_DGRAM};
}
use _plat_specifics::*;
Is this the recommended approach? Any other ideas?