Updated and function for main and sum tests
Add build script
This commit is contained in:
13
src/lib.rs
13
src/lib.rs
@@ -3,6 +3,7 @@ use wasm_bindgen::prelude::*;
|
||||
extern crate web_sys;
|
||||
|
||||
mod utils;
|
||||
mod main;
|
||||
|
||||
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
|
||||
// allocator.
|
||||
@@ -20,11 +21,23 @@ extern {
|
||||
fn alert(s: &str);
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
fn sum(a: i32, b: i32) -> i32;
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn greet() {
|
||||
alert("Hey, CUBETIQ Solution!");
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn just_sum() -> i32 {
|
||||
let sum = sum(100, 50);
|
||||
log(&format!("Just Sum {} + {} = {}", 100, 50, sum));
|
||||
return sum;
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn log(s: &str) {
|
||||
web_sys::console::log_1(&s.into());
|
||||
|
||||
11
src/main.rs
Normal file
11
src/main.rs
Normal file
@@ -0,0 +1,11 @@
|
||||
fn main() {
|
||||
let a = 10;
|
||||
let b = 5;
|
||||
let sum = sum(a, b);
|
||||
|
||||
println!("Sum of {} + {} = {}", a, b, sum);
|
||||
}
|
||||
|
||||
pub fn sum(a: i32, b: i32) -> i32 {
|
||||
a + b
|
||||
}
|
||||
Reference in New Issue
Block a user