A REPL for Rust!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Dylan Baker 04480c66d7 Gitea's Markdown renderer doesn't like `- ####` 4 weeks ago
src Clap can show a default argument for me 4 weeks ago
.gitignore Initial commit 4 weeks ago
Cargo.lock Change package name 4 weeks ago
Cargo.toml Update name 4 weeks ago
LICENSE Add license 4 weeks ago
README.md Gitea's Markdown renderer doesn't like `- ####` 4 weeks ago



Rust REPL is a command-line tool to run some Rust code quickly in a REPL environment, similar to what interepretated languages like Lisp, Python, and Ruby provide.

This REPL should function as you expect for the most part. There are a couple of special features to note though. First, unlike in Rust source files, you can omit semi-colons and they will be inserted for you automatically before being given to rustc. Second, the REPL provides two commands, p! and d!, which are syntactic sugar for println("{}", <var>) and println("{:?}", <var>), respectively (p for ‘print’ and d for ‘debug’). For example:

rust> p! "hello world"
hello world
rust> d! "hello world".find('h')

How Does It Work?

The code you enter into the REPL gets wrapped in fn main() { ... }, written to a file, and given to rustc. The REPL then shells out to the resulting binary and captures any output. All lines of code in a given REPL session are written to the same file, which allows you to reference variables from previous lines. For example:

rust> let x = 5
rust> let y = x + 1
rust> p! x
rust> p! y

The only exception to this is that calls to print! and println! (which includes usage of the p! and d! commands) are discarded after running so as to not clutter up the rest of the session.


Explicit Printing

Normally, entering a value into a REPL prints that value right back at you without you having to specify that you want to print it. For example:

python> 5 + 5

Rust REPL currently requires you to explicitly print anything you want to be printed. Since it works by shelling out to rustc, it doesn’t have direct access to the return values of your expressions, only to whatever gets written to stdout. I’m exploring the idea of automatically insert calls to println! for you, but since not all expressions can be printed, I need to do some experimentation.

Isolated Execution Context

There is currently no way to run a REPL in the context of a Rust project, like Lisp developers will be used to doing. Again, this might happen in the future but probably not any time soon.


$ git clone https://git.simulacrum.party/simulacrumparty/rust-repl
$ cd rust-repl
$ cargo install --path .


    rust-repl [OPTIONS]

    -h, --help       Prints help information
    -V, --version    Prints version information

    -d, --directory <DIRECTORY>    The directory where Rust REPL should store files.
                                   Default: ~/.rust-repl


This software is provided under the terms of the MIT License