This is an automated email from the ASF dual-hosted git repository.
csantanapr pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/incubator-openwhisk-runtime-rust.git
The following commit(s) were added to refs/heads/master by this push:
new 7a75366 Added the "hello" to the example, added badges to README (#5)
7a75366 is described below
commit 7a753666b73cce0c944e052ce550f137fec5df38
Author: Michele Sciabarra <[email protected]>
AuthorDate: Sun Mar 10 12:41:42 2019 +0100
Added the "hello" to the example, added badges to README (#5)
* modified action signature and changed example action
* format code
* changed response error message for action loop
* change error msg
* refactored error messages
* Update README.md
* updated the example
* badges - closes #1
* ops
---
README.md | 4 ++++
example/hello/Cargo.toml | 4 +++-
example/hello/src/lib.rs | 33 ++++++++++++++++++++++-----------
rust1.32/compile | 4 ++++
4 files changed, 33 insertions(+), 12 deletions(-)
diff --git a/README.md b/README.md
index d4e48bc..6b71be7 100644
--- a/README.md
+++ b/README.md
@@ -1,13 +1,17 @@
# incubator-openwhisk-runtime-rust
Work in Progress! Do not use yet...
+It will be awesome.
+[](http://www.apache.org/licenses/LICENSE-2.0)
+[](https://travis-ci.org/apache/incubator-openwhisk-runtime-rust)
# Work Done
- implemented the actionloop
- implemented the Docker image
- implemented the action compiler
+- refactored to a more rustacean form
# Work to do
diff --git a/example/hello/Cargo.toml b/example/hello/Cargo.toml
index 315401c..86a58df 100644
--- a/example/hello/Cargo.toml
+++ b/example/hello/Cargo.toml
@@ -2,7 +2,9 @@
name = "actions"
version = "0.1.0"
authors = ["Roberto Diaz <[email protected]>"]
+edition = "2018"
[dependencies]
serde_json = "1.0"
-
+serde = "1.0"
+serde_derive = "1.0"
diff --git a/example/hello/src/lib.rs b/example/hello/src/lib.rs
index 5f43e8d..732e23b 100644
--- a/example/hello/src/lib.rs
+++ b/example/hello/src/lib.rs
@@ -1,16 +1,27 @@
extern crate serde_json;
-use std::collections::HashMap;
-use serde_json::Value;
+use serde_derive::{Deserialize, Serialize};
+use serde_json::{Error, Value};
-pub fn main(args: HashMap<String, Value>) -> HashMap<String, Value> {
- let name_opt = args.get("name");
- let name = if name_opt.is_some() {
- name_opt.unwrap().as_str().unwrap()
- } else {
- "stranger"
+#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
+struct Input {
+ #[serde(default = "stranger")]
+ name: String,
+}
+
+#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
+struct Output {
+ greeting: String,
+}
+
+fn stranger() -> String {
+ "stranger".to_string()
+}
+
+pub fn main(args: Value) -> Result<Value, Error> {
+ let input: Input = serde_json::from_value(args)?;
+ let output = Output {
+ greeting: format!("Hello, {}", input.name),
};
- let mut out = HashMap::new();
- out.insert("greeting".to_string(), Value::String(format!("Hello, {}",
name)));
- out
+ serde_json::to_value(output)
}
diff --git a/rust1.32/compile b/rust1.32/compile
index 650904e..88a05d7 100755
--- a/rust1.32/compile
+++ b/rust1.32/compile
@@ -43,9 +43,13 @@ def copy_replace(src, dst, match=None, replacement=""):
cargo_action = """[package]
name = "actions"
version = "0.1.0"
+authors = ["Roberto Diaz <[email protected]>"]
+edition = "2018"
[dependencies]
serde_json = "1.0"
+serde = "1.0"
+serde_derive = "1.0"
"""
def build(tgt_dir):