Coder Social home page Coder Social logo

asl-rust's Introduction

asl

crates.io docs.rs build status

This library provides an implementation of Amazon States Language (ASL) in Rust.

The library can parse and execute state machines defined in ASL.

Example: Hello world

This example will print the strings Hello and World:

struct TaskHandler {}
impl StateExecutionHandler for TaskHandler {
    type TaskExecutionError = String;

    fn execute_task(
        &self,
        resource: &str,
        input: &Value,
        credentials: Option<&Value>,
    ) -> Result<Option<Value>, Self::TaskExecutionError> {
        let result = match resource {
            "SayHello" => "Hello",
            "SayWorld" => "World",
            _ => Err("Unknown resource!")?,
        };
        println!("{}", result);
        Ok(None) // We opt into returning nothing
    }
}

fn main() {
    let definition = r#"{
          "Comment": "A simple minimal example of the States language",
          "StartAt": "State: Hello",
          "States": {
            "State: Hello": {
              "Type": "Task",
              "Resource": "SayHello",
              "Next": "State: World"
            },
            "State: World": {
              "Type": "Task",
              "Resource": "SayWorld",
              "End": true
            }
          }
        }"#;
    let state_machine = StateMachine::parse(definition).unwrap();
    let input = Value::Null;
    let execution: Execution<TaskHandler, EmptyContext> = state_machine.start(&input, TaskHandler {}, EmptyContext {});
    // the Execution type implements Iterator, so we can iterate until there are no more states to execute
    let steps: Vec<StateExecutionOutput> = execution.collect();
}

See: test_hello_world.rs.

Amazon States Language (ASL)

The Amazon States Language is a JSON-based, structured language used to define your state machine, a collection of states, that can do work (Task states), determine which states to transition to next (Choice states), stop an execution with an error (Fail states), and so on.

For a complete definition of ASL, refer to the Amazon States Language Specification.

IMPORTANT: This project is NOT affiliated with Amazon in any way.

ASL is deeply connected to AWS Step Functions. This means that in many places, the definition from the language specification is not specified, so this library opts into following the results from AWS Step Functions.

Feature Matrix

The main features that are already implemented or missing are listed in the following table:

Feature Status
State execution workflow Implemented
JSON Paths and Reference Paths Implemented
States: Pass Implemented
States: Wait Implemented
States: Fail Implemented
States: Choice Implemented
States: Succeed Implemented
States: Task Implemented, but not all features. See other features in this table.
States: Task - Timeout Not implemented (#9)
States: Task - Hearbeat Not implemented (#10)
States: Task - Retry Not implemented (#11)
State: Parallel Not Implemented (#2)
State: Map Not Implemented (#1)
Intrinsic Functions Not Implemented (#4)

License

This project is licensed under the MIT License.

asl-rust's People

Contributors

edisongustavo avatar

Watchers

 avatar  avatar

asl-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.