Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extra crate rust-ini;
- use ini::Ini;
- use std::thread;
- #[derive(Debug)]
- pub struct Hosts<'a> {
- key: &'a str,
- ip: &'a str,
- username: &'a str,
- password: String
- }
- fn main() {
- let conf = match Ini::load_from_file("host.ini") {
- Ok(c) => c,
- Err(e) => {
- dbg!(e);
- return
- }
- };
- let (hosts, path) = match config::load_cfg(&conf) {
- Some(l) => l,
- None => return
- };
- println!("{:?}, {:?}", hosts, path);
- for host in hosts {
- thread::spawn(move || {
- println!("{}", host.ip);
- });
- }
- }
- mod config {
- fn load_cfg<'a>(conf: &'a Ini) -> Option<(Vec<super::Hosts<'a>>, &'a str)> {
- let mut hosts = Vec::new();
- let path = conf.get_from(Some("path"), "path").unwrap();
- for prop in conf.section(Some("test")) {
- for (k, v) in prop.into_iter() {
- let vals: Vec<&str> = v.split(',').collect();
- let host = super::Hosts {
- key: k,
- ip: vals[0],
- username: vals[1],
- password: vals[2].to_string()
- };
- hosts.push(host);
- }
- }
- Some((hosts,path))
- }
- }
Add Comment
Please, Sign In to add comment