From 0ae0b214bc9c1195c0a3d687c8c3d6fdbff539a0 Mon Sep 17 00:00:00 2001 From: Sambo Chea Date: Thu, 20 Aug 2020 15:27:50 +0700 Subject: [PATCH] Add math mod for lib --- math/.gitignore | 7 +++++++ math/Cargo.toml | 9 +++++++++ math/src/lib.rs | 16 ++++++++++++++++ src/lib.rs | 1 - src/main.rs | 11 ----------- www/index.ts | 3 +++ 6 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 math/.gitignore create mode 100644 math/Cargo.toml create mode 100644 math/src/lib.rs delete mode 100644 src/main.rs diff --git a/math/.gitignore b/math/.gitignore new file mode 100644 index 0000000..dd41acf --- /dev/null +++ b/math/.gitignore @@ -0,0 +1,7 @@ +/target +**/*.rs.bk +Cargo.lock +bin/ +pkg/ +wasm-pack.log +.cargo-ok \ No newline at end of file diff --git a/math/Cargo.toml b/math/Cargo.toml new file mode 100644 index 0000000..1e2af50 --- /dev/null +++ b/math/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "math" +version = "0.1.0" +authors = ["Sambo Chea "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/math/src/lib.rs b/math/src/lib.rs new file mode 100644 index 0000000..4983dfa --- /dev/null +++ b/math/src/lib.rs @@ -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); + } +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 0aae62e..e930c9a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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. diff --git a/src/main.rs b/src/main.rs deleted file mode 100644 index 3b6fe19..0000000 --- a/src/main.rs +++ /dev/null @@ -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 -} \ No newline at end of file diff --git a/www/index.ts b/www/index.ts index 6e0e00d..a93688d 100644 --- a/www/index.ts +++ b/www/index.ts @@ -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) \ No newline at end of file