tag | 16468c877ac2f8b94cd60e334b04db7889edeac9 | |
---|---|---|
tagger | David Grove <groved@us.ibm.com> | Wed Aug 11 11:28:51 2021 -0400 |
object | 26dda157bfd72e31d64c101bbf06cc1c34df64b1 |
rust1.34@1.3.0
commit | 26dda157bfd72e31d64c101bbf06cc1c34df64b1 | [log] [tgz] |
---|---|---|
author | David Grove <dgrove-oss@users.noreply.github.com> | Wed Aug 04 09:48:30 2021 -0400 |
committer | GitHub <noreply@github.com> | Wed Aug 04 09:48:30 2021 -0400 |
tree | d23f62c4d9e59a8e3e1e0256fdd8c87aa70e98f7 | |
parent | 3fc2eac494ff858cda2baa8a2f7812a1e5ec0ba6 [diff] |
prep for 1.3.0 release (#34)
To use as a Docker action:
wsk action update myAction my_action.rs --docker openwhisk/action-rust-v1.34
The file my_action.rs
looks like:
extern crate serde_json; use serde_derive::{Deserialize, Serialize}; use serde_json::{Error, Value}; #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] struct Input { #[serde(default = "stranger")] name: String, } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] struct Output { body: 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 { body: format!("Hello, {}", input.name), }; serde_json::to_value(output) }
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
.
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:
|- Cargo.toml |- src |- lib.rs
Here is an example of a Cargo.toml
file
[package] name = "actions" version = "0.1.0" authors = ["John Doe <john@doe.domain>"] edition = "2018" [dependencies] serde_json = "1.0" serde = "1.0" serde_derive = "1.0"
Once you have all your code zipped in a file with the showed folder structure you can generate your action with the following command:
wsk action create yourAction /full_path_to/yourCode.zip --docker openwhisk/action-rust-v1.34