Add math mod for lib

This commit is contained in:
Sambo Chea 2020-08-20 15:27:50 +07:00
parent 39101f2081
commit 0ae0b214bc
6 changed files with 35 additions and 12 deletions

7
math/.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
/target
**/*.rs.bk
Cargo.lock
bin/
pkg/
wasm-pack.log
.cargo-ok

9
math/Cargo.toml Normal file
View File

@ -0,0 +1,9 @@
[package]
name = "math"
version = "0.1.0"
authors = ["Sambo Chea <sombochea@cubetiqs.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

16
math/src/lib.rs Normal file
View File

@ -0,0 +1,16 @@
mod math {
#[allow(dead_code)]
pub fn sum(a: i32, b: i32) -> i32 {
a + b
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
assert_eq!(math::sum(10, 10), 20);
}
}

View File

@ -3,7 +3,6 @@ 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.

View File

@ -1,11 +0,0 @@
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
}

View File

@ -3,3 +3,6 @@ import * as wasm from "./../pkg/wasmweb_sample"
wasm.greet()
wasm.log("[WEB] external logging...")
const sum = wasm.just_sum()
console.log("Sum of number", sum)