refactor: moved wasm feature to wasm32 target build dependencies
authorMA Beaudet <ma@beaudet.xyz>
Tue, 9 Nov 2021 12:22:11 +0000 (13:22 +0100)
committerMA Beaudet <ma@beaudet.xyz>
Tue, 9 Nov 2021 12:22:11 +0000 (13:22 +0100)
Cargo.toml
src/lib.rs

index 23f8cf9..468afe7 100644 (file)
@@ -8,11 +8,12 @@ crate-type = ["cdylib", "rlib"]
 
 [features]
 default = ["rand"]
-wasm = ["wasm-bindgen", "getrandom"]
 
 [dependencies]
 rand = { version = "0.8.4", optional = true }
 rayon = { version = "1.5.1", optional = true }
 serde = { version = "1.0", optional = true, features = ["derive"] }
-wasm-bindgen = { version = "0.2.78", optional = true }
-getrandom = { version = "0.2", features = ["js"], optional = true }
+
+[target.'cfg(target_arch = "wasm32")'.dependencies]
+wasm-bindgen = "0.2.78"
+getrandom = { version = "0.2", features = ["js"] }
index ca04d2f..34e6895 100644 (file)
@@ -22,7 +22,7 @@ use constants::{
 #[cfg(feature = "serde")]
 use serde::{Deserialize, Serialize};
 
-#[cfg(feature = "wasm")]
+#[cfg(target_arch = "wasm32")]
 use wasm_bindgen::prelude::*;
 
 #[derive(Debug)]
@@ -219,7 +219,7 @@ fn find_fast(mut u: u32) -> u16 {
 //     }
 // }
 
-#[cfg_attr(feature = "wasm", wasm_bindgen)]
+#[cfg_attr(target_arch = "wasm32", wasm_bindgen)]
 pub fn parse_cards(s: &str) -> Vec<u32> {
     s.trim()
         .split_whitespace()
@@ -239,7 +239,7 @@ pub fn parse_cards(s: &str) -> Vec<u32> {
 /// assert_eq!(eval_hand(parse_cards("4s 4d 4h 4c 5d")), 140);
 /// assert_eq!(eval_hand(parse_cards("Ts 9s 8s 7s 6s 7h 6d")), 5);
 /// ```
-#[cfg_attr(feature = "wasm", wasm_bindgen)]
+#[cfg_attr(target_arch = "wasm32", wasm_bindgen)]
 pub fn eval_hand(cards: Vec<u32>) -> u16 {
     match cards.len() {
         7 => eval_7hand(&cards.try_into().unwrap()),
@@ -294,7 +294,7 @@ pub fn eval_7hand(hand: &[u32; 7]) -> u16 {
 /// assert_eq!(eval, 1433);
 /// assert_eq!(hand_rank(eval), FLUSH);
 /// ```
-#[cfg_attr(feature = "wasm", wasm_bindgen)]
+#[cfg_attr(target_arch = "wasm32", wasm_bindgen)]
 pub fn hand_rank(i: u16) -> u8 {
     match i {
         6186..=7462 => HIGH_CARD,
@@ -310,7 +310,7 @@ pub fn hand_rank(i: u16) -> u8 {
     }
 }
 
-#[cfg_attr(feature = "wasm-bindgen", wasm_bindgen)]
+#[cfg_attr(target_arch = "wasm32", wasm_bindgen)]
 pub fn frequency(i: u8) -> f32 {
     EXPECTED_FREQ[i as usize] / 2_598_960.
 }