Updated math lib and import in cargo toml file

This commit is contained in:
Sambo Chea 2020-08-20 16:02:30 +07:00
parent 0ae0b214bc
commit cc6b0c38db
5 changed files with 17 additions and 8 deletions

View File

@ -19,6 +19,8 @@ default = ["console_error_panic_hook"]
[dependencies] [dependencies]
wasm-bindgen = "0.2.63" wasm-bindgen = "0.2.63"
math = { path = "math", version = "0.1.0" }
# The `console_error_panic_hook` crate provides better debugging of panics by # The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires # logging them with `console.error`. This is great for development, but requires
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for # all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
@ -37,4 +39,4 @@ wasm-bindgen-test = "0.3.13"
[profile.release] [profile.release]
# Tell `rustc` to optimize for small code size. # Tell `rustc` to optimize for small code size.
opt-level = "s" opt-level = "s"

View File

@ -1,8 +1,6 @@
mod math { #[allow(dead_code)]
#[allow(dead_code)] pub fn sum(a: i32, b: i32) -> i32 {
pub fn sum(a: i32, b: i32) -> i32 { a + b
a + b
}
} }
#[cfg(test)] #[cfg(test)]
@ -11,6 +9,6 @@ mod tests {
#[test] #[test]
fn it_works() { fn it_works() {
assert_eq!(math::sum(10, 10), 20); assert_eq!(sum(10, 10), 20);
} }
} }

6
src/main.rs Normal file
View File

@ -0,0 +1,6 @@
use math;
fn main() {
let sum = math::sum(1, 2);
println!("Sum number {}", sum)
}

View File

@ -1,3 +1,4 @@
#[allow(dead_code)]
pub fn set_panic_hook() { pub fn set_panic_hook() {
// When the `console_error_panic_hook` feature is enabled, we can call the // When the `console_error_panic_hook` feature is enabled, we can call the
// `set_panic_hook` function at least once during initialization, and then // `set_panic_hook` function at least once during initialization, and then
@ -7,4 +8,4 @@ pub fn set_panic_hook() {
// https://github.com/rustwasm/console_error_panic_hook#readme // https://github.com/rustwasm/console_error_panic_hook#readme
#[cfg(feature = "console_error_panic_hook")] #[cfg(feature = "console_error_panic_hook")]
console_error_panic_hook::set_once(); console_error_panic_hook::set_once();
} }

View File

@ -5,6 +5,8 @@
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/math/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/math/target" />
<excludeFolder url="file://$MODULE_DIR$/target" /> <excludeFolder url="file://$MODULE_DIR$/target" />
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />