Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created September 17, 2019 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust-play/617b0d9f0b047b822967375c0653a858 to your computer and use it in GitHub Desktop.
Save rust-play/617b0d9f0b047b822967375c0653a858 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
use std::collections::HashMap;
type Table = HashMap<String, Vec<String>>;
fn show(table : &Table){
for (row, items) in table {
println!("Row : {}", row);
for item in items {
println!("Item : {}", item)
}
}
println!("#####");
}
fn sort(table : &mut Table) {
for (_row, items) in table {
items.sort();
}
println!("#####")
}
fn main(){
let mut table = Table::new();
table.insert("Table1".to_string(), vec!["Pasta".to_string(), "Pizza".to_string()]);
table.insert("Table2".to_string(), vec!["Roti".to_string(), "Panner".to_string()]);
println!("Before Sorting");
show(&table);
sort(&mut table);
println!("After Sorting");
show(&table);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment