Code Monkey home page Code Monkey logo

papyrust's Introduction

Papyrust is a very basic Rust script runner aimed at near zero launch latency. It was written mainly because other such runners I used, which I shall not name, all have at least 100 ms delay before launching the actual script, presumably due to invoking cargo build without even checking for changes in source code.

How to use:

  • Install Papyrust (make sure that $HOME/.cargo/bin is in your PATH):
    cargo install papyrust
  • Create a Cargo project for your Rust script, let's call it x for simplicity:
    cargo init x
  • In the project directory create a shell script named x.pp with Papyrust shebang and make it executable:
    cd x
    echo '#!/usr/bin/env papyrust' > x.pp
    chmod +x x.pp

Now you can simply launch your script directly

./x.pp

or put it in your $HOME/bin, /usr/local/bin or whatever

ln -s /home/coolhacker/devel/x/x.pp ~/bin

if you want to be cool like me and launch it from anywhere.

And the whole point of Papyrust is this:

# First time
time x
   Compiling x v0.1.0 (/home/coolhacker/devel/x)
    Finished release [optimized] target(s) in 0.40s
x  0,34s user 0,08s system 80% cpu 0,515 total

# From now on, until you change the source code
time x
x  0,00s user 0,00s system 86% cpu 0,003 total

When I said "very basic" in the beginning of this very serious document, that wasn't a joke.

  1. Your script must be a full-fledged Cargo project, even if it does absolutely nothing.
  2. The script must be inside your project directory - that's how Papyrust determines where the project is.
  3. The script's base name must match the name of the binary that Cargo produces. That is, if the binary is called supermegafancyemptyproject, you're stuck with supermegafancyemptyproject.pp inside your supermegafancyemptyproject project directory. Yeah. Actually, the extension doesn't matter, since Papyrust ignores it, so you don't have to insert pp into your every script name.
  4. Papyrust only builds your project if any file in src subdirectory is newer than the binary produced by cargo, or if the binary is missing. So if you put some extra files in src after the project was build, e.g. unused modules, the project will be recompiled every time you launch your script. You see, Cargo is too smart and caches the binary along with its last modification time, which will be in the past, because the relevant sources haven't changed, and I don't really want to parse all the mod declarations in your project to figure out which of the sources are relevant.
  5. It only compiles your script in release mode.

So, basically, it just barely works, is aimed exclusively at people too lazy to run cargo build --release or cargo install --path . themselves and, obviously, is not the best example of state-of-the-art idiomatic Rust code.

Good luck ๐Ÿ˜„

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.