Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable Shape::Command only when wasm-bindgen feature is used #41

Merged
merged 2 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,14 @@ wasm-opt = ["-Oz"]

[dev-dependencies]
base64 = "0.21.3"
criterion = "0.4"
qrcode = "0.12.0"

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
criterion = { version = "0.4", default-features = false, features = ["cargo_bench_support", "plotters"]}

[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
criterion = "0.4"

[[bench]]
name = "qr"
harness = false
Expand Down
18 changes: 8 additions & 10 deletions src/convert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@ pub type ModuleFunction = fn(usize, usize, Module) -> String;
#[cfg(all(target_arch = "wasm32", feature = "wasm-bindgen"))]
use wasm_bindgen::prelude::*;

// TODO: Find a way to use the same enum for wasm and not wasm
// Current bug being that wasm_bindgen & #[cfg(not(target_arch = "wasm32"))] are not compatible(?)
/// Different possible Shapes to represent modules in a [`crate::QRCode`]
#[cfg(target_arch = "wasm32")]
#[repr(C)]
#[cfg_attr(feature = "wasm-bindgen", wasm_bindgen)]
#[wasm_bindgen]
#[cfg(feature = "wasm-bindgen")]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd)]
pub enum Shape {
/// Square Shape
Expand All @@ -54,7 +52,7 @@ pub enum Shape {
}

/// Different possible Shapes to represent modules in a [`crate::QRCode`]
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(feature = "wasm-bindgen"))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd)]
pub enum Shape {
/// Square Shape
Expand Down Expand Up @@ -93,6 +91,7 @@ pub enum Shape {
/// </svg>
Command(ModuleFunction),
}

impl From<Shape> for usize {
fn from(shape: Shape) -> Self {
match shape {
Expand All @@ -102,7 +101,7 @@ impl From<Shape> for usize {
Shape::Vertical => 3,
Shape::Horizontal => 4,
Shape::Diamond => 5,
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(feature = "wasm-bindgen"))]
Shape::Command(_) => 6,
}
}
Expand Down Expand Up @@ -133,7 +132,7 @@ impl From<Shape> for &str {
Shape::Vertical => "vertical",
Shape::Horizontal => "horizontal",
Shape::Diamond => "diamond",
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(feature = "wasm-bindgen"))]
Shape::Command(_) => "command",
}
}
Expand Down Expand Up @@ -180,16 +179,15 @@ impl Deref for Shape {
fn deref(&self) -> &Self::Target {
let index: usize = (*self).into();
match self {
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(feature = "wasm-bindgen"))]
Self::Command(func) => func,
_ => &Self::FUNCTIONS[index],
}
}
}

/// Different possible image background shapes
#[cfg_attr(target_arch = "wasm32", repr(C))]
#[cfg_attr(all(target_arch = "wasm32", feature = "wasm-bindgen"), wasm_bindgen)]
#[cfg_attr(feature = "wasm-bindgen", repr(C), wasm_bindgen)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd)]
pub enum ImageBackgroundShape {
/// Square shape
Expand Down