Rust is not yet supported
Even though Rust is not officially supported yet I would still like to capture the parts of its syntax that appear similar to the languages that currently are supported.
#![feature(lookup_host)]
use std::collections;
struct DnsLookupCache {
cache : std::collections::HashMap<Box<String>, Vec<std::net::SocketAddr>>
}
impl DnsLookupCache {
fn new() -> DnsLookupCache {
DnsLookupCache {
cache: std::collections::HashMap::new()
}
}
fn lookup(&mut self, host: &String) -> std::io::Result<&Vec<std::net::SocketAddr>> {
match self.cache.get(host) {
Some(cached) => Ok(cached),
None => {
let mut hosts = Vec::new();
for result in try!(std::net::lookup_host(host)) {
hosts.push(result);
}
let owned_host = host.clone();
self.cache.insert(Box::new(owned_host), hosts);
return self.lookup(host);
}
}
}
}
- Broken pseudo-shebang on the first line
- Broken nested type generic
<Box<String>, Vec<std::net::SocketAddr>>
- There are probably other improvements that can also be added.
Rust is not yet supported
Even though Rust is not officially supported yet I would still like to capture the parts of its syntax that appear similar to the languages that currently are supported.
<Box<String>, Vec<std::net::SocketAddr>>