Rustfmt net crate

This commit is contained in:
Pyfisch 2018-11-03 15:28:48 +01:00
parent ba1ed11ced
commit 2481ad25f8
30 changed files with 4957 additions and 2870 deletions

View file

@ -31,21 +31,32 @@ pub fn replace_host_table(table: HashMap<String, IpAddr>) {
}
pub fn parse_hostsfile(hostsfile_content: &str) -> HashMap<String, IpAddr> {
hostsfile_content.lines().filter_map(|line| {
let mut iter = line.split('#').next().unwrap().split_whitespace();
Some((iter.next()?.parse().ok()?, iter))
}).flat_map(|(ip, hosts)| {
hosts.filter(|host| {
let invalid = ['\0', '\t', '\n', '\r', ' ', '#', '%', '/', ':', '?', '@', '[', '\\', ']'];
host.parse::<Ipv4Addr>().is_err() && !host.contains(&invalid[..])
}).map(move |host| {
(host.to_owned(), ip)
hostsfile_content
.lines()
.filter_map(|line| {
let mut iter = line.split('#').next().unwrap().split_whitespace();
Some((iter.next()?.parse().ok()?, iter))
})
}).collect()
.flat_map(|(ip, hosts)| {
hosts
.filter(|host| {
let invalid = [
'\0', '\t', '\n', '\r', ' ', '#', '%', '/', ':', '?', '@', '[', '\\', ']',
];
host.parse::<Ipv4Addr>().is_err() && !host.contains(&invalid[..])
})
.map(move |host| (host.to_owned(), ip))
})
.collect()
}
pub fn replace_host(host: &str) -> Cow<str> {
HOST_TABLE.lock().unwrap().as_ref()
HOST_TABLE
.lock()
.unwrap()
.as_ref()
.and_then(|table| table.get(host))
.map_or(host.into(), |replaced_host| replaced_host.to_string().into())
.map_or(host.into(), |replaced_host| {
replaced_host.to_string().into()
})
}