Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use petgraph::graphmap::{DiGraphMap}; // 0.4.13
- struct Something {
- exchange: String,
- from: String,
- to: String,
- }
- type GraphType<'a> = DiGraphMap<(&'a str, &'a str), f64>;
- fn main() {
- let mut graph: GraphType = DiGraphMap::new();
- let mut i = 0;
- loop {
- // fetched from user STDIN input
- let something = Something { exchange: "Exchange".to_string(), from: "USD".to_string(), to: "BTC".to_string() };
- add_edges(&mut graph, &something);
- i+= 1;
- if i == 5 {
- break;
- }
- }
- println!("{:?}", graph);
- }
- fn add_edges(graph: &mut GraphType , something: &Something) {
- let a_exchange = something.exchange.clone();
- let b_exchange = something.exchange.clone();
- let a_from = something.from.clone();
- let b_to = something.exchange.clone();
- let edge_a: (&str, &str) = (&a_exchange, &a_from);
- let edge_b: (&str, &str) = (&b_exchange, &b_to);
- graph.add_edge(edge_a, edge_b, 23.);
- }
Add Comment
Please, Sign In to add comment