| 1 |
# Libudev |
| 2 |
This crate provides a safe wrapper around the native `libudev` library. It applies the RAII pattern |
| 3 |
and Rust lifetimes to ensure safe usage of all `libudev` functionality. The RAII pattern ensures |
| 4 |
that all acquired resources are released when they're no longer needed, and Rust lifetimes ensure |
| 5 |
that resources are released in a proper order. |
| 6 |
|
| 7 |
* [Documentation](http://dcuddeback.github.io/libudev-rs/libudev/) |
| 8 |
|
| 9 |
## Dependencies |
| 10 |
In order to use the `libudev` crate, you must have a Linux system with the `libudev` library |
| 11 |
installed where it can be found by `pkg-config`. To install `libudev` on Debian-based Linux |
| 12 |
distributions, execute the following command: |
| 13 |
|
| 14 |
``` |
| 15 |
sudo apt-get install libudev-dev |
| 16 |
``` |
| 17 |
|
| 18 |
`libudev` is a Linux-specific package. It is not available for Windows, OS X, or other operating |
| 19 |
systems. |
| 20 |
|
| 21 |
### Cross-Compiling |
| 22 |
The `libudev` crate can be used when cross-compiling to a foreign target. Details on how to |
| 23 |
cross-compile `libudev` are explained in the [`libudev-sys` crate's |
| 24 |
README](https://github.com/dcuddeback/libudev-sys#cross-compiling). |
| 25 |
|
| 26 |
## Usage |
| 27 |
Add `libudev` as a dependency in `Cargo.toml`: |
| 28 |
|
| 29 |
```toml |
| 30 |
[dependencies] |
| 31 |
libudev = "0.2" |
| 32 |
``` |
| 33 |
|
| 34 |
If you plan to support operating systems other than Linux, you'll need to add `libudev` as a |
| 35 |
target-specific dependency: |
| 36 |
|
| 37 |
```toml |
| 38 |
[target.x86_64-unknown-linux-gnu.dependencies] |
| 39 |
libudev = "0.2" |
| 40 |
``` |
| 41 |
|
| 42 |
Import the `libudev` crate. The starting point for nearly all `libudev` functionality is to create a |
| 43 |
context object. |
| 44 |
|
| 45 |
```rust |
| 46 |
extern crate libudev; |
| 47 |
|
| 48 |
fn main() { |
| 49 |
let context = libudev::Context::new().unwrap(); |
| 50 |
let mut enumerator = libudev::Enumerator::new(&context).unwrap(); |
| 51 |
|
| 52 |
enumerator.match_subsystem("tty").unwrap(); |
| 53 |
|
| 54 |
for device in enumerator.scan_devices().unwrap() { |
| 55 |
println!("found device: {:?}", device.syspath()); |
| 56 |
} |
| 57 |
} |
| 58 |
``` |
| 59 |
|
| 60 |
## Contributors |
| 61 |
* [dcuddeback](https://github.com/dcuddeback) |
| 62 |
* [Susurrus](https://github.com/Susurrus) |
| 63 |
|
| 64 |
## License |
| 65 |
Copyright © 2015 David Cuddeback |
| 66 |
|
| 67 |
Distributed under the [MIT License](LICENSE). |