Giter VIP home page Giter VIP logo

apache / openwhisk-runtime-rust Goto Github PK

View Code? Open in Web Editor NEW
25.0 27.0 18.0 183 KB

Apache OpenWhisk Runtime Rust supports Apache OpenWhisk functions written in Rust

Home Page: https://openwhisk.apache.org/

License: Apache License 2.0

Rust 22.41% Dockerfile 7.60% Makefile 4.31% Python 34.38% Scala 31.30%
openwhisk apache serverless faas functions-as-a-service cloud serverless-architectures serverless-functions docker functions

openwhisk-runtime-rust's Introduction

Apache OpenWhisk Runtime for Rust

License Continuous Integration

Give it a try today

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.

For the return result, not only support A JSON serde Value but also support Array serde Value

So a simple hello array funtion would be:

extern crate serde_json;

use serde_derive::{Deserialize, Serialize};
use serde_json::{Error, Value};


pub fn main(args: Value) -> Result<Value, Error> {
    let output = ["a", "b"];
    serde_json::to_value(output)
}

And support array result for sequence action as well, the first action's array result can be used as next action's input parameter.

So the function can be:

extern crate serde_json;

use serde_derive::{Deserialize, Serialize};
use serde_json::{Error, Value};


pub fn main(args: Value) -> Result<Value, Error> {
    let inputParam = args.as_array();
    let defaultOutput = ["c", "d"];
    match inputParam {
        None => serde_json::to_value(defaultOutput),
        Some(x) => serde_json::to_value(x),
    }
}

Managing dependencies

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 <[email protected]>"]
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

openwhisk-runtime-rust's People

Contributors

dgrove-oss avatar jbampton avatar ningyougang avatar rabbah avatar rdiaz82 avatar sciabarracom avatar upgle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

openwhisk-runtime-rust's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.