netrc-parser

Crates.ionetrc-parser
lib.rsnetrc-parser
version0.1.1
created_at2025-05-17 17:13:42.323096+00
updated_at2025-05-17 18:39:17.759542+00
descriptionA Rust library for parsing and manipulating .netrc files
homepage
repositoryhttps://github.com/dantescur/netrc-parser
max_upload_size
id1678007
size77,256
Daniel (Dantescur)

documentation

README

netrc-parser

CI

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.

Installation

Add to your Cargo.toml:

[dependencies]
netrc-parser = "0.1.0"

Usage

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(())
}

Run the example

cargo run --example simple

Documentation

Run cargo doc --open to view the API documentation.

Development

Format code with rustfmt nightly

rustup toolchain install nightly
rustup component add rustfmt --toolchain nightly
cargo +nightly fmt

License

Licensed under the MIT. See LICENSE for details.

Contributing

Contributions are welcome! Please open a issue or pull request on Github

Commit count: 20

cargo fmt