Ask coding questions

← Back to all posts
Rust import packages on repl?
teymour

I'm currently reading up on rust, and trying to run through some examples on repl.it. I have, however, yet to figure out how to install packages. Does anyone know how to import rust packages (crates) into repl.it.

Answered by jfrank11 [earned 5 cycles]
View Answer
Voters
AndG1
sbagdat
Kudos
NeonRaspberry
amasad
AlexWayfer
billbuchanan
DMeechan
ScottyThePilot
mojebi
Comments
hotnewtop
jfrank11

It looks like they are making improvements or it has been possible ever since who knows. But here is how I managed (you might need a paid account for this would be nice if someone with a free account could check):
Open a shell (question mark on the lower right or (Shift-Cmd/Ctrl-S)

enter the following:

Voilà!

joojeene

@jfrank11 that's really useful!
Worked for me except for the
cargo init projectname
where I got this:

So I had to experiment and had success with:
> USER=runner cargo init projectname

teymour

@jfrank11 Thanks. That does the trick.

NeonRaspberry
  1. Make a new Repl Rust project
  2. In the terminal, type bash
  3. Type cargo new {project name}
  4. You should now see a new folder, navigate to the src file inside it and find the main.rs file. DO NOT CLICK RUN TO RUN YOUR PROGRAM!!! IT WILL ONLY RUN THE ORIGINAL main.rs FILE!
  5. To test run your new Cargo project, type cd {project name} in the terminal, and use command cargo run.
  6. If the run succeeds, open Cargo.toml and add
  1. Add use rand::Rng in main.rs
  2. You're good to go!
TejasUmesh

found a better method;
just type

into your shell and everytime you wanna run your code type

and you're gold!

marco_p_v_vezzoli

This would be really useful. In order to write a program which is not a toy I definitely need this