Created
August 21, 2019 00:04
-
-
Save rust-play/b1bc15aaa6c7f36a634624a0b33ab845 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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