Ask coding questions

← Back to all posts
Rust import packages on repl?
CaptainAnon (150)

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

Answered by jfrank11 (7) [earned 5 cycles]
View Answer
jfrank11 (7)

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)

> cargo init helloworld
> cd helloworld
> vi Cargo.toml
put `markdown = "0.2"` under `[dependencies]`
> vi src/

enter the following:

extern crate markdown;

fn main() {
    let html : String = markdown::to_html("__I am markdown__");

    println!("{:?}", html);
> cargo run

[email protected]:~/Hello-World/helloworld$ cargo run
   Compiling helloworld v0.1.0 (/home/runner/Hello-World/helloworld)
    Finished dev [unoptimized + debuginfo] target(s) in 3.20s
     Running `target/debug/helloworld`
"<p><strong>I am markdown</strong></p>\n"


joojeene (0)

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

> cargo init projectname
error: Failed to create package `projectname` at `

Caused by:
  could not determine the current user, please set $USER

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

CaptainAnon (150)

@jfrank11 Thanks. That does the trick.

AndrewBota (1)
  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 file. DO NOT CLICK RUN TO RUN YOUR PROGRAM!!! IT WILL ONLY RUN THE ORIGINAL 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
rand = "{latest version of rand}"
  1. Add use rand::Rng in
  2. You're good to go!
TejasUmesh (0)

found a better method;
just type

cargo init

into your shell and everytime you wanna run your code type

cargo run

and you're gold!

marco_p_v_vezzoli (0)

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