Guest User

Untitled

a guest
Jan 19th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. extra crate rust-ini;
  2.  
  3. use ini::Ini;
  4. use std::thread;
  5.  
  6. #[derive(Debug)]
  7. pub struct Hosts<'a> {
  8. key: &'a str,
  9. ip: &'a str,
  10. username: &'a str,
  11. password: String
  12. }
  13.  
  14.  
  15. fn main() {
  16. let conf = match Ini::load_from_file("host.ini") {
  17. Ok(c) => c,
  18. Err(e) => {
  19. dbg!(e);
  20. return
  21. }
  22. };
  23.  
  24. let (hosts, path) = match config::load_cfg(&conf) {
  25. Some(l) => l,
  26. None => return
  27. };
  28.  
  29. println!("{:?}, {:?}", hosts, path);
  30.  
  31. for host in hosts {
  32. thread::spawn(move || {
  33. println!("{}", host.ip);
  34. });
  35. }
  36. }
  37.  
  38. mod config {
  39. fn load_cfg<'a>(conf: &'a Ini) -> Option<(Vec<super::Hosts<'a>>, &'a str)> {
  40. let mut hosts = Vec::new();
  41. let path = conf.get_from(Some("path"), "path").unwrap();
  42. for prop in conf.section(Some("test")) {
  43. for (k, v) in prop.into_iter() {
  44. let vals: Vec<&str> = v.split(',').collect();
  45. let host = super::Hosts {
  46. key: k,
  47. ip: vals[0],
  48. username: vals[1],
  49. password: vals[2].to_string()
  50. };
  51. hosts.push(host);
  52. }
  53. }
  54.  
  55. Some((hosts,path))
  56. }
  57. }
Add Comment
Please, Sign In to add comment