Guest User

Untitled

a guest
Jan 22nd, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. use petgraph::graphmap::{DiGraphMap}; // 0.4.13
  2.  
  3. struct Something {
  4. exchange: String,
  5. from: String,
  6. to: String,
  7. }
  8.  
  9.  
  10. type GraphType<'a> = DiGraphMap<(&'a str, &'a str), f64>;
  11. fn main() {
  12. let mut graph: GraphType = DiGraphMap::new();
  13.  
  14. let mut i = 0;
  15. loop {
  16. // fetched from user STDIN input
  17. let something = Something { exchange: "Exchange".to_string(), from: "USD".to_string(), to: "BTC".to_string() };
  18.  
  19. add_edges(&mut graph, &something);
  20.  
  21. i+= 1;
  22. if i == 5 {
  23. break;
  24. }
  25. }
  26.  
  27.  
  28. println!("{:?}", graph);
  29. }
  30.  
  31. fn add_edges(graph: &mut GraphType , something: &Something) {
  32. let a_exchange = something.exchange.clone();
  33. let b_exchange = something.exchange.clone();
  34.  
  35. let a_from = something.from.clone();
  36. let b_to = something.exchange.clone();
  37.  
  38. let edge_a: (&str, &str) = (&a_exchange, &a_from);
  39. let edge_b: (&str, &str) = (&b_exchange, &b_to);
  40.  
  41. graph.add_edge(edge_a, edge_b, 23.);
  42. }
Add Comment
Please, Sign In to add comment