From 8e30e146e011afd3c522c0392bf1963022fef0f5 Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Thu, 3 Mar 2022 13:23:52 -0500 Subject: [PATCH] cleanup + cfg-if --- Cargo.toml | 1 + src/lib.rs | 39 +++++++++++++++++++-------------------- src/main.rs | 1 - 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c5a9fdf..198df76 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,6 +27,7 @@ eframe = { git = "https://github.com/Titaniumtown/egui", default-features = fals include-flate = { git = "https://github.com/Titaniumtown/include-flate.git" } shadow-rs = { version = "0.9", default-features = false } const_format = { version = "0.2.22", default-features = false, features = ["fmt"] } +cfg-if = "1.0.0" [build-dependencies] shadow-rs = "0.9" diff --git a/src/lib.rs b/src/lib.rs index a54ef04..39eed1f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,33 +1,32 @@ #![allow(clippy::unused_unit)] // Fixes clippy keep complaining about wasm_bindgen #![feature(const_mut_refs)] -#![feature(total_cmp)] mod egui_app; mod function; mod misc; -#[cfg(target_arch = "wasm32")] -use misc::log_helper; -#[cfg(target_arch = "wasm32")] -use wasm_bindgen::prelude::*; +cfg_if::cfg_if! { + if #[cfg(target_arch = "wasm32")] { + use misc::log_helper; + use wasm_bindgen::prelude::*; -#[cfg(target_arch = "wasm32")] -#[global_allocator] -static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; + #[global_allocator] + static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; -#[cfg(target_arch = "wasm32")] -#[wasm_bindgen] -pub fn start(canvas_id: &str) -> Result<(), wasm_bindgen::JsValue> { - log_helper("Initializing..."); + #[wasm_bindgen] + pub fn start(canvas_id: &str) -> Result<(), wasm_bindgen::JsValue> { + log_helper("Initializing..."); - // Used in order to hook into `panic!()` to log in the browser's console - log_helper("Initializing panic hooks..."); - std::panic::set_hook(Box::new(console_error_panic_hook::hook)); - log_helper("Initialized panic hooks!"); + // Used in order to hook into `panic!()` to log in the browser's console + log_helper("Initializing panic hooks..."); + std::panic::set_hook(Box::new(console_error_panic_hook::hook)); + log_helper("Initialized panic hooks!"); - log_helper("Finished initializing!"); + log_helper("Finished initializing!"); - log_helper("Starting App..."); - let app = egui_app::MathApp::default(); - eframe::start_web(canvas_id, Box::new(app)) + log_helper("Starting App..."); + let app = egui_app::MathApp::default(); + eframe::start_web(canvas_id, Box::new(app)) + } + } } diff --git a/src/main.rs b/src/main.rs index 99b1fae..82167f8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,4 @@ #![feature(const_mut_refs)] -#![feature(total_cmp)] mod egui_app; mod function;