feat: add nix demo

This commit is contained in:
2023-01-19 23:23:44 +08:00
parent 2e256c32f8
commit d1b1132cc3
4 changed files with 94 additions and 1 deletions

View File

@@ -103,6 +103,7 @@ Project or files:
│   └── sana
├── __linux
│   ├── ipipe
│   ├── nix-demo
│   ├── notify
│   ├── psutil
│   ├── sysinfo
@@ -263,6 +264,6 @@ Project or files:
├── vec.rs
└── while.rs
232 directories, 39 files
233 directories, 39 files
```

69
__linux/nix-demo/Cargo.lock generated Normal file
View File

@@ -0,0 +1,69 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "autocfg"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "libc"
version = "0.2.139"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"
[[package]]
name = "memoffset"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4"
dependencies = [
"autocfg",
]
[[package]]
name = "nix"
version = "0.26.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfdda3d196821d6af13126e40375cdf7da646a96114af134d5f417a9a1dc8e1a"
dependencies = [
"bitflags",
"cfg-if",
"libc",
"memoffset",
"pin-utils",
"static_assertions",
]
[[package]]
name = "nix-demo"
version = "0.1.0"
dependencies = [
"nix",
]
[[package]]
name = "pin-utils"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "static_assertions"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"

View File

@@ -0,0 +1,9 @@
[package]
name = "nix-demo"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
nix = "0.26.2"

View File

@@ -0,0 +1,14 @@
use nix::unistd::{getgid, gethostname, getpid, getuid};
fn main() {
let hostname = gethostname().unwrap();
println!("Hostname: {}", hostname.to_string_lossy());
let pid = getpid();
println!("Pid: {}", pid);
let uid = getuid();
println!("Uid: {}", uid);
let gid = getgid();
println!("Gid: {}", gid);
}