Nix seeks to provide friendly bindings to various *nix platform APIs (Linux, Darwin, ...). The goal is to not provide a 100% unified interface, but to unify what can be while still providing platform specific APIs.
For many system APIs, Nix provides a safe alternative to the unsafe APIs exposed by the libc crate. This is done by wrapping the libc functionality with types/abstractions that enforce legal/safe usage.
As an example of what Nix provides, examine the differences between what is exposed by libc and nix for the gethostname system call:
// libc api (unsafe, requires handling return code/errno)
pub unsafe extern fn gethostname(name: *mut c_char, len: size_t) -> c_int;
// nix api (returns a nix::Result)
pub fn gethostname(name: &mut [u8]) -> Result<()>;
To use nix
, first add this to your Cargo.toml
:
[dependencies]
nix = "0.6.0"
Then, add this to your crate root:
extern crate nix;
Contributions are very welcome. Please See CONTRIBUTING for additional details.
Nix is licensed under the MIT license. See LICENSE for more details.