Giter Club home page Giter Club logo

pipelines's Introduction

๐Ÿšฐ Waterworks

waterworks is a library for building pipelines of chained computations, with a focus on being explicit about opting in as a stage of a given pipeline and for a quick and convenient way of inspecting the output of each stage and acting on that output to potentially terminate the pipeline early.

It was designed to be used for the flow of data in a compiler, and is put to "production" use in my personal compiler project, catastrophic.

Usage

Usage of waterworks first requires defining the individual stages that the overall computation pipeline will be put together with.

A stage is defined by the Error type global to the pipeline, the input and output of that specific stage, and the run method for performing the actual computation.

For example, if we were constructing a compiler we might have an initial file parsing stage like so:

struct FileParseStage;

impl Stage<CompileError> for FileParseStage {
    type Input = PathBuf;
    type Output = Ast;

    fn run(self, input: PathBuf) -> Result<Ast, CompileError> {
        parse_file(input)
    }
}

This can then be put together into a full pipleine, chained into adsitional compilation stages:

let pipe = pipeline(FileParseStage, |_| ())
    .and_then(AstAnalysisStage, |_| ())
    .and_then(OptimisationStage, |_| ())
    .and_then(ComppilationStage, |_| ());

Callbacks

The pipeline construction and chaining methods both take a callback in addition to the stage being attached to the pipeline. This callback can be used to both inspect the result of the associated stage and to terminate the execution of the pipeline early.

For example, say you wanted a compiler flag that simply logged the output of the parser and then returned - you could implement that with the following callback when attaching the FileParseStage above:

|ast| if log_ast {
    println!("{:?}", ast);
    Continue::Cancel
} else {
    Continue::Continue
}

For convenience in trivial cases, a ()-returning closure is treated as if it was explicitly returning Continue::Continue

Running

To then run a pipeline, it's a simple case of calling run, passing in the first stage's defined input. This will then return a result of either the output of the final stage in the pipeline, the first error that gets returned by a stage, or whether the pipeline was cancelled early.

let result = pipe.run("waterworks.rs");

pipelines's People

Contributors

samuelsleight avatar

Stargazers

Ari avatar

Watchers

James Cloos avatar  avatar

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.