You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2022/07/26 02:53:30 UTC

[GitHub] [openwhisk-runtime-rust] ningyougang commented on pull request #39: Support array result include sequence action

ningyougang commented on PR #39:
URL: https://github.com/apache/openwhisk-runtime-rust/pull/39#issuecomment-1194933642

   The rust supports sequence action by default, test steps as below
   * Write split.rs and sort.rs
   ```rust
   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 {
       greeting: String,
   }
   
   fn stranger() -> String {
       "stranger".to_string()
   }
   
   pub fn main(args: Value) -> Result<Value, Error> {
       // has no split, just return array, need to receive this value in next action(sort)
       let output = ["a", "b"];
       serde_json::to_value(output)
   }
   
   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 {
       greeting: String,
   }
   
   fn stranger() -> String {
       "stranger".to_string()
   }
   
   pub fn main(args: Value) -> Result<Value, Error> {
       println!("param args is {}", args);
   
       let inputParam = args.as_array();
       println!("input param as array is {:?}", inputParam);
   
       let defaultOutput = ["finally-a", "finally-b"];
       match inputParam {
          None => serde_json::to_value(defaultOutput),
          Some(x) => serde_json::to_value(x),
       }
   }
   ```
   * Create the action and invoke it
   ```shell
   wsk -i action create /whisk.system/utils/split-rust --kind rust:1.34 ~/split.rs
   wsk -i action create /whisk.system/utils/sort-rust --kind rust:1.34 ~/sort.rs
   wsk -i action create mySequence-rust --sequence /whisk.system/utils/split-rust,/whisk.system/utils/sort-rust
   wsk -i action invoke --result mySequence-rust -r -v
   ```
   
   refer to: https://docs.serde.rs/serde_json/value/enum.Value.html


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@openwhisk.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org