extern crate cfg_if; extern crate wasm_bindgen; mod utils; use cfg_if::cfg_if; use wasm_bindgen::prelude::*; cfg_if! { // When the `wee_alloc` feature is enabled, use `wee_alloc` as the global // allocator. if #[cfg(feature = "wee_alloc")] { extern crate wee_alloc; #[global_allocator] static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; } } #[wasm_bindgen] pub fn should_handle(url: String) -> bool { if url.ends_with(".css") || url.ends_with(".js") || url.ends_with(".png") || url.ends_with(".jpg") { false } else { true } } let result = format!("{}{}", "Well yes", format!("Or {} no?", "possibly")); #[wasm_bindgen] pub fn page(url: String) -> String { html( header(&format!("wasm-page: {}", &url)), body(format!( "{}{}", "

Hello from Rust & wasm!

", format!( "", &url ) )) ) } fn header(title: &str) -> String { head(element("title", title)) } fn html(head: String, body: String) -> String { element("html", &format!("{}\n{}", head, body)) } fn head(content: String) -> String { element("head", &content) } fn body(content: String) -> String { element("body", &content) } fn element(name: &str, content: &str) -> String { format!("<{}>{}", name, content, name) }