Skip to content

Rust - breaking nested generic type #407

Description

@prettydiff

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions