i'm taking a break

This commit is contained in:
2022-12-03 01:32:10 +01:00
parent 3cdb4b991d
commit 8186283cf6
3 changed files with 53 additions and 30 deletions

View File

@@ -7,5 +7,3 @@ edition = "2021"
[dependencies] [dependencies]
rfd = "0.10.0" rfd = "0.10.0"
phf = { version = "0.11", default-features = false }

View File

@@ -55,4 +55,29 @@ static COUNTRIES: phf::Map<&'static str, &'static str> = phf_map! {
"US" => "United States", "US" => "United States",
"UK" => "United Kingdom", "UK" => "United Kingdom",
}; };
``` ```
this gave some issues when trying to import the crate (something with the macro's).
I couldn't find the fix for this in the documentation so i decided in the end to go back to the ugly but native solution
example of the errors:
```
error[E0432]: unresolved import `phf::phf_map`
--> src\main.rs:5:5
|
5 | use phf::phf_map;
| ^^^^^^^^^^^^ no `phf_map` in the root
```
```
error: cannot determine resolution for the macro `phf_map`
--> src\main.rs:7:49
|
7 | pub static scores: phf::Map<&'static str, u8> = phf_map! (
| ^^^^^^^
|
= note: import resolution is stuck, try simplifying macro imports
```

View File

@@ -1,14 +1,14 @@
use std::collections::HashMap; use std::collections::HashMap;
use std::fs::File; use std::fs::File;
use std::io::{BufRead, BufReader}; use std::io::{BufRead, BufReader};
use phf::phf_map; use std::iter::Iterator;
static scores: phf::Map<&'static str, u8> = phf_map! ( pub const scores:HashMap<&str, u32> = HashMap::from([
"A" => 1, //rock ("A",1), //rock
"B" => 2, //paper ("B",2), //paper
"C" => 3, //scizzors ("C",3) //scizzors
); ]);
// figuring out a way to do this :/ // figuring out a way to do this :/
// 1 2 = lose // 1 2 = lose
@@ -18,27 +18,27 @@ static scores: phf::Map<&'static str, u8> = phf_map! (
// 3 1 = lose // 3 1 = lose
// 3 2 = win // 3 2 = win
static possibilities: phf::Map<&'static u8, &'static u8> = phf_map! { static possibilities: HashMap<u32,u32> = HashMap::from([
12 => 0, (12,0),
13 => 6, (13,6),
21 => 6, (21,6),
23 => 0, (23,0),
31 => 0, (31,0),
32 => 6, (32,6),
11 => 3, (11,3),
22 => 3, (22,3),
33 => 3, (33,3)
}; ]);
static shape_map: phf::Map<&'static String, &'static String> = phf_map! { static shape_map: HashMap<&str, &str> = [
"X" => "A", ("X","A"),
"Y" => "B", ("Y","B"),
"Z" => "C", ("Z","C")
}; ].iter().cloned().collect();
struct Play { struct Play {
them: u8, them: u32,
you: u8 you: u32
} }
@@ -63,9 +63,9 @@ fn main() {
fn parse_line(line: String) -> Play { fn parse_line(line: String) -> Play {
let mut temp = line.split(' ').collect::<Vec<&str>>(); let mut temp = line.split(' ').collect::<Vec<&str>>();
return Play {them: scores[temp[0].parse().unwrap()], you: scores[temp[1].parse().unwrap()] } return Play {them: scores[temp[0]].clone(), you: scores[temp[1]].clone() }
} }
fn get_score(p: Play) -> u8 { fn get_score(p: Play) -> u32 {
return possibilities[p.you*10+p.them]+scores[p.you]; return possibilities[&(p.you*10+p.them)]+&p.you;
} }