Expand description
Augeas bindings for Rust
Augeas is a library for reading, modifying, and writing a structured file, like configuration files.
This library is a low-level binding to the C API of Augeas, with a few abstractions to make it more idiomatic to use in Rust. It does not aim to provide a high-level API to manipulate configuration files, but rather to provide a safe and idiomatic way to interact with Augeas.
The main differences with the C API are:
- Add
clearandclearmmethods clear values (instead of passing anOptiontoset/setm). - Add
touchmethod to create a node if it does not exist. - Use a
Spanstruct to represent the span of a node in a file. - Use a
Positionenum to indicate where to insert a new node. - Use an
Attrstruct to represent the attributes of a node. - Use a
SaveModeenum to indicate how to save changes.
§Usage
In Cargo.toml:
[dependencies]
raugeas = "1.0.0"§Summary
A typical interaction looks like this:
use raugeas::{Augeas, Flags};
let mut aug = Augeas::init(Some("/"), "", Flags::NONE).unwrap();
// Get the ip address for host.example.com from `/etc/hosts`.
let entry = aug.get("etc/hosts/*[canonical = 'host.example.com']/ip")?;
if let Some(ip) = entry {
println!("The ip for host.example.com is {}", ip);
} else {
println!("There is no entry for host.example.com in /etc/hosts");
}
// Add an alias for host.example.com.
aug.set(
"etc/hosts/*[canonical = 'host.example.com']/alias[last()+1]",
"server.example.com",
)?;Re-exports§
pub use error::Error;
Modules§
- error
- Error types for the library
Structs§
- Attr
- Attributes of a node
- Augeas
- The handle for the Augeas library.
- Flags
- Flag to be passed to the
Augeas::initmethod. - OsAttr
- Attributes of a node
- OsSpan
- A span in the tree.
- Span
- A span in the tree.
Enums§
- Commands
Number - Outcome of a successful
sruncommand. - Position
- The insert position.
- Save
Mode - Parameters for the save modes.
Type Aliases§
- Result
- Shortcut for the result type used in this crate.