utmp_rs/
lib.rs

1//! A Rust crate for parsing `utmp` files like `/var/run/utmp` and `/var/log/wtmp`.
2//!
3//! ## Usage
4//!
5//! Simplest way is to use `parse_from_*` functions,
6//! which returns a `Vec<UtmpEntry>` on success:
7//! ```
8//! # use anyhow::Result;
9//! # fn main() -> Result<()> {
10//! let entries = utmp_rs::parse_from_path("/var/run/utmp")?;
11//! // ...
12//! # Ok(())
13//! # }
14//! ```
15//!
16//! If you don't need to collect them all,
17//! `UtmpParser` can be used as an iterator:
18//! ```
19//! # use anyhow::Result;
20//! use utmp_rs::UtmpParser;
21//! # fn main() -> Result<()> {
22//! for entry in UtmpParser::from_path("/var/run/utmp")? {
23//!     let entry = entry?;
24//!     // ...
25//! }
26//! # Ok(())
27//! # }
28//! ```
29//!
30//! All the `parse_from_*` functions as well as `UtmpParser` parse `utmp` file
31//! based on the native format for the target platform.
32//! If cross-platform parsing is needed,
33//! `Utmp32Parser` or `Utmp64Parser` can be used instead of `UtmpParser`.
34
35mod entry;
36mod parse;
37
38pub use entry::{UtmpEntry, UtmpError};
39pub use parse::{parse_from_file, parse_from_path, parse_from_reader};
40pub use parse::{ParseError, Utmp32Parser, Utmp64Parser, UtmpParser};