From 3778352d3900d053aa1693ea1c71459670fdf62d Mon Sep 17 00:00:00 2001 From: losfair Date: Tue, 8 Oct 2019 23:01:03 +0800 Subject: [PATCH] Update a few examples. --- Cargo.lock | 4 ++++ Cargo.toml | 3 ++- examples/hello_world/Cargo.toml | 9 +++++++++ examples/hello_world/src/main.rs | 7 +++++++ examples/iterative_hash/src/main.rs | 2 +- 5 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 examples/hello_world/Cargo.toml create mode 100644 examples/hello_world/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 5f15df164..b1b20a08f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -610,6 +610,10 @@ dependencies = [ "unicode-segmentation 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "hello_world" +version = "0.1.0" + [[package]] name = "hex" version = "0.3.2" diff --git a/Cargo.toml b/Cargo.toml index bbd596087..dd5b48b6a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -58,7 +58,8 @@ members = [ "lib/wasi-tests", "lib/emscripten-tests", "lib/middleware-common-tests", - "examples/plugin-for-example" + "examples/plugin-for-example", + "examples/hello_world" ] [build-dependencies] diff --git a/examples/hello_world/Cargo.toml b/examples/hello_world/Cargo.toml new file mode 100644 index 000000000..a71d719ed --- /dev/null +++ b/examples/hello_world/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "hello_world" +version = "0.1.0" +authors = ["losfair "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/examples/hello_world/src/main.rs b/examples/hello_world/src/main.rs new file mode 100644 index 000000000..ca24b9cea --- /dev/null +++ b/examples/hello_world/src/main.rs @@ -0,0 +1,7 @@ +fn main() { + for i in 0..8 { + let s = format!("Hello, {}", i); + println!("{}", s); + } + panic!("OK"); +} diff --git a/examples/iterative_hash/src/main.rs b/examples/iterative_hash/src/main.rs index 043bc02a1..66ed10405 100644 --- a/examples/iterative_hash/src/main.rs +++ b/examples/iterative_hash/src/main.rs @@ -20,7 +20,7 @@ fn main() { let diff = millis - last_millis; if diff >= 100 { record_count += 1; - println!("{}", (i - round_count) as f64 / diff as f64); + println!("{}", ((i - round_count) as u128) * 1000000 / diff ); last_millis = millis; round_count = i; }