Skip to content

Commit 20dc889

Browse files
committed
Add document for support array result
1 parent 3e282f5 commit 20dc889

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,43 @@ pub fn main(args: Value) -> Result<Value, Error> {
6262

6363
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`.
6464

65+
For the return result, not only support `A JSON serde Value` but also support `Array serde Value`
66+
67+
So a simple `hello array` funtion would be:
68+
69+
```rust
70+
extern crate serde_json;
71+
72+
use serde_derive::{Deserialize, Serialize};
73+
use serde_json::{Error, Value};
74+
75+
76+
pub fn main(args: Value) -> Result<Value, Error> {
77+
let output = ["a", "b"];
78+
serde_json::to_value(output)
79+
}
80+
```
81+
82+
And support array result for sequence action as well, the first action's array result can be used as next action's input parameter.
83+
84+
So the function can be:
85+
86+
```rust
87+
extern crate serde_json;
88+
89+
use serde_derive::{Deserialize, Serialize};
90+
use serde_json::{Error, Value};
91+
92+
93+
pub fn main(args: Value) -> Result<Value, Error> {
94+
let inputParam = args.as_array();
95+
let defaultOutput = ["c", "d"];
96+
match inputParam {
97+
None => serde_json::to_value(defaultOutput),
98+
Some(x) => serde_json::to_value(x),
99+
}
100+
}
101+
```
65102
### Managing dependencies
66103

67104
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:

0 commit comments

Comments
 (0)