File: README.md

package info (click to toggle)
rust-sysctl 0.5.5-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 216 kB
  • sloc: makefile: 4
file content (63 lines) | stat: -rw-r--r-- 1,803 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
This crate provides a safe interface for reading and writing information to the kernel using the sysctl interface.

[![Build Status](https://api.cirrus-ci.com/github/johalun/sysctl-rs.svg)](https://cirrus-ci.com/github/johalun/sysctl-rs/master)

[![Current Version](https://img.shields.io/crates/v/sysctl.svg)](https://crates.io/crates/sysctl)


*FreeBSD, Linux, macOS and iOS are supported.*
*Contributions for improvements and other platforms are welcome.*

### Documentation

Documentation is available on [docs.rs](https://docs.rs/sysctl)

### Usage

Add to `Cargo.toml`

```toml
[dependencies]
sysctl = "*"
```

### macOS/iOS

* Due to limitations in the sysctl(3) API, many of the methods of
  the `Ctl` take a mutable reference to `self` on macOS/iOS.
* Sysctl descriptions are not available on macOS/iOS and Linux.
* Some tests failures are ignored, as the respective sysctls do not
  exist on macos.

### Example

sysctl comes with several examples, see the examples folder:

* `value.rs`: shows how to get a sysctl value
* `value_as.rs`: parsing values as structures
* `value_string.rs`: parsing values as string. Use this for cross platform compatibility since all sysctls are strings on Linux.
* `value_oid_as.rs`: getting a sysctl from OID constants from the `libc` crate.
* `set_value.rs`: shows how to set a sysctl value
* `struct.rs`: reading data into a struct
* `temperature.rs`: parsing temperatures
* `iterate.rs`: showcases iteration over the sysctl tree

Run with:

```sh
$ cargo run --example iterate
```

Or to use in your program:

```rust
extern crate sysctl;
use sysctl::Sysctl;

fn main() {
    let ctl = sysctl::Ctl::new("kern.osrevision").unwrap();
    println!("Description: {}", ctl.description().unwrap());
    println!("Value: {}", ctl.value_string().unwrap());
}
```