Add math mod for lib
This commit is contained in:
parent
39101f2081
commit
0ae0b214bc
7
math/.gitignore
vendored
Normal file
7
math/.gitignore
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
/target
|
||||||
|
**/*.rs.bk
|
||||||
|
Cargo.lock
|
||||||
|
bin/
|
||||||
|
pkg/
|
||||||
|
wasm-pack.log
|
||||||
|
.cargo-ok
|
9
math/Cargo.toml
Normal file
9
math/Cargo.toml
Normal 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
16
math/src/lib.rs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
@ -3,7 +3,6 @@ use wasm_bindgen::prelude::*;
|
|||||||
extern crate web_sys;
|
extern crate web_sys;
|
||||||
|
|
||||||
mod utils;
|
mod utils;
|
||||||
mod main;
|
|
||||||
|
|
||||||
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
|
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
|
||||||
// allocator.
|
// allocator.
|
||||||
|
11
src/main.rs
11
src/main.rs
@ -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
|
|
||||||
}
|
|
@ -3,3 +3,6 @@ import * as wasm from "./../pkg/wasmweb_sample"
|
|||||||
|
|
||||||
wasm.greet()
|
wasm.greet()
|
||||||
wasm.log("[WEB] external logging...")
|
wasm.log("[WEB] external logging...")
|
||||||
|
|
||||||
|
const sum = wasm.just_sum()
|
||||||
|
console.log("Sum of number", sum)
|
Loading…
Reference in New Issue
Block a user