1

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.

MarianD
  • 13,096
  • 12
  • 42
  • 54
Dash83
  • 1,357
  • 2
  • 17
  • 31

1 Answers1

3

This function is only available on Unix when the unix feature is activated.

And How to activate a feature

In your case just add this to your cargo manifest:

[dependencies.socket2]
version = "0.3.7"
features = ["unix"]
Stargateur
  • 24,473
  • 8
  • 65
  • 91