Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created August 21, 2019 00:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust-play/b1bc15aaa6c7f36a634624a0b33ab845 to your computer and use it in GitHub Desktop.
Save rust-play/b1bc15aaa6c7f36a634624a0b33ab845 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
use std::collections::HashMap;
pub struct Selector {
pub networks: HashMap<u32, Vec<&'static str>>,
}
impl Selector {
pub fn new() -> Selector {
Selector {
networks: [
(0, vec!["0.0.0.0/0"]),
(1918, vec!["10.0.0.0/8", "192.168.0.0/16"]),
(1337, vec!["8.8.8.8/32"]),
].iter().cloned().collect()
}
}
pub fn get_generation(&self, x: u32) -> Vec<&'static str>
{
let default = vec!["128.200.0.0/16", "1.2.3.0/24"];
match self.networks.get(&x) {
Some(n) => n.to_owned(),
None => {
// Log here if you want ...
default
}
}
}
}
fn main() {
let dd = Selector::new();
let ip_list = dd.get_generation(1919);
println!("{:?}", ip_list);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment