I'm trying to build a Unix-domain socket using the socket2 crate and the most basic code fails to compile:
extern crate socket2;
use socket2::*;
fn main() {
let socket = Socket::new(Domain::unix(), Type::dgram(), None).unwrap();
}
This is the error:
5 | let socket = Socket::new(Domain::unix(), Type::dgram(), None).unwrap(); | ^^^^^^^^^^^^ function or associated item not found in `socket2::Domain`
The documentation indicates, that unix function is "only available on Unix when the unix feature is activated". I'm running this code on a Ubuntu machine. Do I need to activate anything else in my cargo file for this function to be enabled? The crate lacks examples that I can rely on.
This function is only available on Unix when the
unix
feature is activated.
In your case just add this to your cargo manifest:
[dependencies.socket2]
version = "0.3.7"
features = ["unix"]