Crates.io | netrc-parser |
lib.rs | netrc-parser |
version | 0.1.1 |
created_at | 2025-05-17 17:13:42.323096+00 |
updated_at | 2025-05-17 18:39:17.759542+00 |
description | A Rust library for parsing and manipulating .netrc files |
homepage | |
repository | https://github.com/dantescur/netrc-parser |
max_upload_size | |
id | 1678007 |
size | 77,256 |
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 simple
Run cargo doc --open
to view the API documentation.
rustup toolchain install nightly
rustup component add rustfmt --toolchain nightly
cargo +nightly fmt
Licensed under the MIT. See LICENSE for details.
Contributions are welcome! Please open a issue or pull request on Github