Using an interactive shell (REPL)

Rust:
Using an interactive shell (REPL)

How to:

As of now, Rust does not have an official REPL shipped with it. You can use third-party tools like evcxr_repl. Install it with Cargo:

cargo install evcxr_repl

Then, run the REPL:

evcxr

Inside, test some Rust code:

let x = 5;
let y = 3;
println!("{} + {} = {}", x, y, x + y);

Output should be:

5 + 3 = 8

Deep Dive

Rust’s ethos is centered around safety and performance, which are usually associated with ahead-of-time compiled languages, and less with interpreted, REPL-friendly ones. Historically, languages like Python or Ruby prioritized having a REPL for immediate feedback, but weren’t designed with system-level tasks in mind.

Despite the absence of an official REPL in Rust, a couple of alternatives like evcxr_repl have emerged. These projects are not just hacking Rust into a REPL; they’re smartly weaving together the language’s compile-and-run cycle into an interactive session. The REPL compiles the code behind the scenes and runs the binary, capturing the output. This way, it preserves Rust’s performance benefits while still giving that interactive experience.

There’s ongoing discussion in the Rust community about official REPL support, and with every language iteration, we see more tooling sophistication that might eventually lead to a native solution.

See Also

For more info and other tools: