Main.rs not working

Hello all, I am totally new to rust / rustup. I purchased a book on the subject which arrived yesterday znd set to work. The first program, naturally, is hello world. I followed the book letter by letter and when I tried to run the program, called main.rs, nothing happened. I will try to attach the terminal here. (I am using ubuntu 16.04).
rod@rod:~$ cd projects

rod@rod:~/projects$ cd hello_world

rod@rod:~/projects/hello_world$ main.rs

main.rs: command not found

rod@rod:~/projects/hello_world$ ls

main.rs
As you can see, the main.rs exists but when I try to open it, I am told command not found even though it shows in the ls-l (List).
Being totally new to this, could you perhaps show me where I have gone wrong.

Thank you.

Greetings, and thanks for your interest!

To run the program written in Rust, you must first compile it - the source files themselves aren't executable. If this is a standalone source file (or a simple package without dependencies, only with some modules), you can use rustc directly, as said here:

rustc main.rs
./main

The first command will compile the source file using some default parameters, one of which is an output name - it will be identical to the source file name, but without extension (or with extension .exe, if you were on Windows). The second - executes the compiled program.

When you will have something more complex, it would be very helpful to make yourself familiar with Cargo - see this chapter in the main Rust book or the book dedicated to Cargo entirely.

Good luck!

4 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.