Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![allow(unused)]
- fn main() {
- use std::collections::HashMap;
- let mut map: HashMap<[i64; 2], String> = HashMap::new();
- map.insert([1,1], String::from("1x1"));
- map.insert([1,2], String::from("1x2"));
- map.insert([1,3], String::from("1x3"));
- let str = "13";
- // Ugly as hell - how do I make this more rust-like?
- let a = cast_to_i64(str.chars().nth(0));
- let b = cast_to_i64(str.chars().nth(1));
- if a.is_none() || b.is_none() {
- print!("nothing is good");
- return;
- }
- if let Some(x) = map.get_mut(&[a.unwrap(),b.unwrap()]) {
- print!("got it: {}, ", x);
- *x = String::from("1x4");
- }
- if let Some(x) = map.get_mut(&[a.unwrap(),b.unwrap()]) {
- print!("again: got it: {}", x);
- }
- }
- fn cast_to_i64(c: Option<char>) -> Option<i64> {
- if c.is_none() || c.unwrap().to_digit(10).is_none() {
- return None;
- }
- let digit = c.unwrap().to_digit(10).unwrap() as i64;
- return Some(digit);
- }
Add Comment
Please, Sign In to add comment