Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created October 2, 2019 08:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust-play/c334c9aa1980e78aa710ec9cb1b716a7 to your computer and use it in GitHub Desktop.
Save rust-play/c334c9aa1980e78aa710ec9cb1b716a7 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
use std::collections::HashMap;
use std::str;
fn main() {
let s = "a, 100\nb, 200\nw, 20";
let mut m = HashMap::new();
s.split('\n').map(|line| {
let v: Vec<_>= line.split(',').map(str::trim).collect();
println!("{:?}", v);
if v.len() == 2 {
m.insert(v[0], v[1]);
}
}).collect();
println!("{:?}", m);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment