diff --git a/build.rs b/build.rs index 1606e99..dbcdf2b 100644 --- a/build.rs +++ b/build.rs @@ -1,30 +1,33 @@ use std::env; pub fn main() { - if cfg!(all(feature = "web_sys", feature = "std_web")) { - panic!("Yew_router does not allow the `web_sys` and `std_web` cargo features to be used simultaneously"); - } else if cfg!(not(any(feature = "web_sys", feature = "std_web"))) { - panic!("Yew_router requires selecting either the `web_sys` or `std_web` cargo feature"); + let using_web_sys = cfg!(feature = "web_sys"); + let using_std_web = cfg!(feature = "std_web"); + if using_web_sys && using_std_web { + panic!("Yew does not allow the `web_sys` and `std_web` cargo features to be used simultaneously"); + } else if !using_web_sys && !using_std_web { + panic!("Yew requires selecting either the `web_sys` or `std_web` cargo feature"); } let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_default(); let using_wasi = target_os == "wasi"; - let cargo_web = env::var("COMPILING_UNDER_CARGO_WEB").unwrap_or_default(); - let using_cargo_web = cargo_web == "1"; - if using_cargo_web && cfg!(feature = "web_sys") { + let using_cargo_web = env::var("COMPILING_UNDER_CARGO_WEB").is_ok(); + if using_cargo_web && using_web_sys { panic!("cargo-web is not compatible with web-sys"); } let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default(); let using_wasm_bindgen = target_arch == "wasm32" && !using_cargo_web && !using_wasi; - if using_wasm_bindgen { - println!("cargo:rustc-cfg=feature=\"wasm_bindgen_test\""); - } else if cfg!(all(feature = "web_sys", not(feature = "doc_test"))) { + + let using_clippy = env::var("CLIPPY_ARGS").is_ok(); + let running_doc_tests = cfg!(feature = "doc_test"); + + if !using_wasm_bindgen && using_web_sys && !running_doc_tests && !using_clippy { let target = env::var("TARGET").unwrap_or_default(); panic!( "Selected target `{}` is not compatible with web-sys", target ); } -} +} \ No newline at end of file diff --git a/src/service.rs b/src/service.rs index 12f3e11..dd0ec0f 100644 --- a/src/service.rs +++ b/src/service.rs @@ -185,15 +185,15 @@ where log::trace!("History state is empty"); None }) - .and_then(|state_string| -> Option>{ + .and_then(|state_string| -> Option { serde_json::from_str(&state_string) .ok() .or_else(|| { log::error!("Could not deserialize state string"); None }) + .and_then(std::convert::identity) // flatten }) - .and_then(std::convert::identity) // flatten .unwrap_or_default(); Route { route: route_string,