Crates.io | unixism |
lib.rs | unixism |
version | 0.1.0 |
source | src |
created_at | 2024-04-05 10:08:31.958522 |
updated_at | 2024-04-05 10:08:31.958522 |
description | A set of tools for working with linux from Rust. |
homepage | |
repository | |
max_upload_size | |
id | 1197196 |
size | 16,319 |
cargo add unixism
Parsing an /etc/resolv.conf
file.
use unixism::dns;
fn main() {
let config = dns::resolv::parse_default().unwrap();
for nameserver in config.nameservers {
println!("{}", nameserver.to_string());
}
for domain in config.search_domains {
println!("{domain}");
}
for option in config.options {
match option {
dns::resolv::ConfigOption::Timeout(timeout) => {
println!("timeout: {timeout}");
}
_ => {}
}
}
}
Parsing any kind of io::Read
type.
use std::fs;
use unixism::dns;
fn main() {
let config = dns::resolv::parse(fs::File::open("local.conf").unwrap()).unwrap();
for nameserver in config.nameservers {
println!("{}", nameserver.to_string());
}
for domain in config.search_domains {
println!("{domain}");
}
for option in config.options {
match option {
dns::resolv::ConfigOption::Timeout(timeout) => {
println!("timeout: {timeout}");
}
_ => {}
}
}
}
Parsing an /etc/hosts
file.
use unixism::hosts;
fn main() {
for host in hosts::parse_default().unwrap() {
println!("ip: {}, names: {:#?}", host.ip, host.names);
}
}
Parsing any kind of io::Read
type.
use std::fs;
use unixism::hosts;
fn main() {
for host in hosts::parse(fs::File::open("local.conf").unwrap()).unwrap() {
println!("ip: {}, names: {:#?}", host.ip, host.names);
}
}