A Rust library for parsing and manipulating .netrc files.
netrc-parser provides a modern, idiomatic parser for .netrc files, supporting machine entries, login credentials, accounts, and macro definitions (macdef). It includes serialization to JSON and TOML, file I/O, and comprehensive error handling.
Add to your Cargo.toml:
[dependencies]
netrc-parser = "0.1.0"Parse a .netrc file and retrieve credentials:
use netrc_parser::{Netrc, NetrcError};
fn main() -> Result<(), NetrcError> {
let path = dirs::home_dir()
.ok_or_else(|| NetrcError::FileNotFound("Home directory not found".to_string()))?
.join(".netrc");
let netrc = Netrc::parse_from_path(&path)?;
if let Some(creds) = netrc.get("surge.surge.sh") {
println!("Login: {}, Password: {}", creds.login, creds.password);
}
Ok(())
}cargo run --example simpleRun cargo doc --open to view the API documentation.
rustup toolchain install nightly
rustup component add rustfmt --toolchain nightly
cargo +nightly fmtLicensed under the MIT. See LICENSE for details.
Contributions are welcome! Please open a issue or pull request on Github