Skip to content

Commit 7a75366

Browse files
sciabarracomcsantanapr
authored andcommitted
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
1 parent 4427257 commit 7a75366

File tree

4 files changed

+33
-12
lines changed

4 files changed

+33
-12
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
# incubator-openwhisk-runtime-rust
22

33
Work in Progress! Do not use yet...
4+
It will be awesome.
45

6+
[![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0)
7+
[![Build Status](https://travis-ci.org/apache/incubator-openwhisk-runtime-rust.svg?branch=master)](https://travis-ci.org/apache/incubator-openwhisk-runtime-rust)
58

69
# Work Done
710

811
- implemented the actionloop
912
- implemented the Docker image
1013
- implemented the action compiler
14+
- refactored to a more rustacean form
1115

1216
# Work to do
1317

example/hello/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
name = "actions"
33
version = "0.1.0"
44
authors = ["Roberto Diaz <roberto@theagilemonkeys.com>"]
5+
edition = "2018"
56

67
[dependencies]
78
serde_json = "1.0"
8-
9+
serde = "1.0"
10+
serde_derive = "1.0"

example/hello/src/lib.rs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
11
extern crate serde_json;
22

3-
use std::collections::HashMap;
4-
use serde_json::Value;
3+
use serde_derive::{Deserialize, Serialize};
4+
use serde_json::{Error, Value};
55

6-
pub fn main(args: HashMap<String, Value>) -> HashMap<String, Value> {
7-
let name_opt = args.get("name");
8-
let name = if name_opt.is_some() {
9-
name_opt.unwrap().as_str().unwrap()
10-
} else {
11-
"stranger"
6+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7+
struct Input {
8+
#[serde(default = "stranger")]
9+
name: String,
10+
}
11+
12+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13+
struct Output {
14+
greeting: String,
15+
}
16+
17+
fn stranger() -> String {
18+
"stranger".to_string()
19+
}
20+
21+
pub fn main(args: Value) -> Result<Value, Error> {
22+
let input: Input = serde_json::from_value(args)?;
23+
let output = Output {
24+
greeting: format!("Hello, {}", input.name),
1225
};
13-
let mut out = HashMap::new();
14-
out.insert("greeting".to_string(), Value::String(format!("Hello, {}", name)));
15-
out
26+
serde_json::to_value(output)
1627
}

rust1.32/compile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,13 @@ def copy_replace(src, dst, match=None, replacement=""):
4343
cargo_action = """[package]
4444
name = "actions"
4545
version = "0.1.0"
46+
authors = ["Roberto Diaz <roberto@theagilemonkeys.com>"]
47+
edition = "2018"
4648
4749
[dependencies]
4850
serde_json = "1.0"
51+
serde = "1.0"
52+
serde_derive = "1.0"
4953
"""
5054

5155
def build(tgt_dir):

0 commit comments

Comments
 (0)