Skip to content

Commit 4382a6d

Browse files
rdiaz82rabbah
authored andcommitted
update readme with usage instructions (#16)
Co-Authored-By: rodric rabbah <rodric@gmail.com>
1 parent 08ecf7a commit 4382a6d

File tree

1 file changed

+67
-3
lines changed

1 file changed

+67
-3
lines changed

README.md

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,74 @@
1616
# limitations under the License.
1717
#
1818
-->
19-
# openwhisk-runtime-rust
20-
21-
Work in Progress... It will be awesome!
19+
# Apache OpenWhisk Runtime for Rust
2220

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

24+
### Give it a try today
25+
To use as a Docker action:
26+
27+
```
28+
wsk action update myAction my_action.rs --docker openwhisk/actionloop-rust-v1.34
29+
```
30+
31+
The file `my_action.rs` looks like:
32+
33+
```
34+
extern crate serde_json;
35+
36+
use serde_derive::{Deserialize, Serialize};
37+
use serde_json::{Error, Value};
38+
39+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
40+
struct Input {
41+
#[serde(default = "stranger")]
42+
name: String,
43+
}
44+
45+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
46+
struct Output {
47+
body: String,
48+
}
49+
50+
fn stranger() -> String {
51+
"stranger".to_string()
52+
}
53+
54+
pub fn main(args: Value) -> Result<Value, Error> {
55+
let input: Input = serde_json::from_value(args)?;
56+
let output = Output {
57+
body: format!("Hello, {}", input.name),
58+
};
59+
serde_json::to_value(output)
60+
}
61+
```
62+
63+
The action is mainly composed by a `main` function that accepts a JSON `serdes Value` as input and returns a `Result` including a JSON `serde Value`.
64+
65+
### Managing dependencies
66+
67+
If your action needs external dependencies, you need to provide a zip file including your source and your cargo file with all your dependencies. The folder structure is the following:
68+
```
69+
|- Cargo.toml
70+
|- src
71+
|- lib.rs
72+
```
73+
Here is an example of a `Cargo.toml` file
74+
```
75+
[package]
76+
name = "actions"
77+
version = "0.1.0"
78+
authors = ["John Doe <john@doe.domain>"]
79+
edition = "2018"
80+
81+
[dependencies]
82+
serde_json = "1.0"
83+
serde = "1.0"
84+
serde_derive = "1.0"
85+
```
86+
Once you have all your code zipped in a file with the showed folder structure you can generate your action with the following command:
87+
```
88+
wsk action create yourAction /full_path_to/yourCode.zip --docker openwhisk/actionloop-rust-v1.34
89+
```

0 commit comments

Comments
 (0)