Skip to content

Commit

Permalink
fix(wasm): Fix nolog feature for wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreBelling committed Nov 25, 2019
1 parent ceaeba6 commit 3160de6
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions src/log.rs
Original file line number Diff line number Diff line change
@@ -1,63 +1,63 @@
#[allow(unused_macros)]

cfg_if! {
if #[cfg(feature = "wasm")] {
use web_sys;
use web_sys::Performance;

if #[cfg(feature = "nolog")] {
macro_rules! log {
($($t:tt)*) => (web_sys::console::log_1(&format_args!($($t)*).to_string().into()))
($($t:tt)*) => ()
}

macro_rules! elog {
($($t:tt)*) => (web_sys::console::log_1(&format_args!($($t)*).to_string().into()))
($($t:tt)*) => ()
}

macro_rules! log_verbose {
($($t:tt)*) => (if $crate::verbose_flag() { web_sys::console::log_1(&format_args!($($t)*).to_string().into()) })
($($t:tt)*) => ()
}

macro_rules! elog_verbose {
($($t:tt)*) => (if $crate::verbose_flag() { web_sys::console::log_1(&format_args!($($t)*).to_string().into()) })
($($t:tt)*) => ()
}

pub struct Stopwatch {
start: f64,
perf: Performance
}
pub struct Stopwatch {}

impl Stopwatch {
pub fn new() -> Stopwatch {
let perf = web_sys::window().unwrap().performance().unwrap();
Stopwatch { start: perf.now(), perf }
}

pub fn elapsed(&self) -> f64 {
(self.perf.now() - self.start) / 1000.0
Stopwatch {}
}
}
} else if #[cfg(feature = "nolog")] {
} else if #[cfg(feature = "wasm")] {
use web_sys;
use web_sys::Performance;

macro_rules! log {
($($t:tt)*) => ()
($($t:tt)*) => (web_sys::console::log_1(&format_args!($($t)*).to_string().into()))
}

macro_rules! elog {
($($t:tt)*) => ()
($($t:tt)*) => (web_sys::console::log_1(&format_args!($($t)*).to_string().into()))
}

macro_rules! log_verbose {
($($t:tt)*) => ()
($($t:tt)*) => (if $crate::verbose_flag() { web_sys::console::log_1(&format_args!($($t)*).to_string().into()) })
}

macro_rules! elog_verbose {
($($t:tt)*) => ()
($($t:tt)*) => (if $crate::verbose_flag() { web_sys::console::log_1(&format_args!($($t)*).to_string().into()) })
}

pub struct Stopwatch {}
pub struct Stopwatch {
start: f64,
perf: Performance
}

impl Stopwatch {
pub fn new() -> Stopwatch {
Stopwatch {}
let perf = web_sys::window().unwrap().performance().unwrap();
Stopwatch { start: perf.now(), perf }
}

pub fn elapsed(&self) -> f64 {
(self.perf.now() - self.start) / 1000.0
}
}
} else {
Expand Down

0 comments on commit 3160de6

Please sign in to comment.