Skip to content

AlexandreCotorobai/Rust_CSLP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust Tutorial

CSLP - Group 7

  • Alexandre Cotorobai - 107849
  • Joaquim Rosa - 109089
  • Bernardo Figueiredo - 108073

Requirements

Rust Installation: https://www.rust-lang.org/tools/install

Getting Started

Installing rustup on Linux or macOS

$ curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh

Compiling and running a Rust program

To create a project we will be using a Rust’s build system and package manager named Cargo.

Check if cargo is installed:

$ cargo --version

If so you can create a project with this simple command:

$ cargo new hello_cargo

Cargo has generated a “Hello, world!” program for you. The project Cargo generated placed the code in the src directory and we have a Cargo.toml configuration file in the top directory.

Cargo expects your source files to live inside the src directory. The top-level project directory is just for README files, license information, configuration files, and anything else not related to your code. Using Cargo helps you organize your projects. There’s a place for everything, and everything is in its place.

$ cargo build
   Compiling hello_cargo v0.1.0 (file:///projects/hello_cargo)
    Finished dev [unoptimized + debuginfo] target(s) in 2.85 secs

From hello_cargo directory, this command creates an executable file in target/debug/hello_cargo (or target\debug\hello_cargo.exe on Windows) rather than in your current directory. You can run the created executable using ./target/debug/hello_cargo.

We can also use cargo run to compile the code and then run the resultant executable all in one command:

$ cargo run
   Compiling hello_cargo v0.1.0 (file:///projects/hello_cargo)
    Finished dev [unoptimized + debuginfo] target(s) in 0.33 secs
     Running `target/debug/hello_cargo`

Hello, world!

cargo check is also a powerfull command that quickly checks your code to make sure it compiles but doesn’t produce an executable (good for checking if your work still compiles).

About

Rust Tutorial for CSLP class 23/24

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages