diff --git a/web/Cargo.toml b/web/Cargo.toml index e38ed39..d99c863 100644 --- a/web/Cargo.toml +++ b/web/Cargo.toml @@ -3,6 +3,11 @@ name = "web" version = "0.1.0" edition = "2021" +[features] +ssr = [] +web = [] +default = ["web"] + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] diff --git a/web/src/service.rs b/web/src/service.rs index c81ef72..5319005 100644 --- a/web/src/service.rs +++ b/web/src/service.rs @@ -15,7 +15,7 @@ use std::collections::BTreeMap; use crate::{console_debug, console_error, console_log}; -use reqwasm::http::{self}; +use reqwasm::http; use sycamore::prelude::*; use web_sys::{window, Storage}; diff --git a/web/src/typings.rs b/web/src/typings.rs index f52b0e7..456fc61 100644 --- a/web/src/typings.rs +++ b/web/src/typings.rs @@ -31,10 +31,14 @@ extern "C" { macro_rules! console_log { // Note that this is using the `log` function imported above during // `bare_bones` - ($($t:tt)*) => {{ - use crate::typings::log; - (log(&format_args!($($t)*).to_string())) - }} + ($($t:tt)*) => { + if cfg!(feature="web") { + use crate::typings::log; + log(&format_args!($($t)*).to_string()); + } else if cfg!(feature="ssr") { + println!($($t)*); + } + } } #[macro_export] @@ -42,27 +46,43 @@ macro_rules! console_debug { // Note that this is using the `log` function imported above during // `bare_bones` ($($t:tt)*) => {{ - use crate::typings::debug; - (debug(&format_args!($($t)*).to_string())) + if cfg!(feature="web") { + use crate::typings::debug; + debug(&format_args!($($t)*).to_string()); + } else if cfg!(feature="ssr") { + print!("DEBUG: "); + println!($($t)*); + } }} } #[macro_export] macro_rules! console_error { - // Note that this is using the `log` function imported above during + // Note that this is using the `error` function imported above during // `bare_bones` ($($t:tt)*) => {{ - use crate::typings::error; - (error(&format_args!($($t)*).to_string())) + if cfg!(feature="web") + { + use crate::typings::error; + error(&format_args!($($t)*).to_string()); + }else if cfg!(feature="ssr") { + print!("ERROR: "); + println!($($t)*); + }; }} } #[macro_export] macro_rules! console_warn { - // Note that this is using the `log` function imported above during + // Note that this is using the `warn` function imported above during // `bare_bones` ($($t:tt)*) => {{ - use crate::typings::warn; - (warn(&format_args!($($t)*).to_string())) + if cfg!("web") { + use crate::typings::warn; + (warn(&format_args!($($t)*).to_string())) + } else if cfg!(feature="ssr") { + print!("WARN: "); + (println!($($t)*)) + } }} }