Your First Rust Lab

RustRustBeginner
Practice Now

Introduction

Hi there, welcome to LabEx! In this first lab, you'll learn the classic "Hello, World!" program in Rust.

Click the Continue button below to start the lab.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL rust(("`Rust`")) -.-> rust/FunctionsandClosuresGroup(["`Functions and Closures`"]) rust/FunctionsandClosuresGroup -.-> rust/function_syntax("`Function Syntax`") rust/FunctionsandClosuresGroup -.-> rust/expressions_statements("`Expressions and Statements`") subgraph Lab Skills rust/function_syntax -.-> lab-101055{{"`Your First Rust Lab`"}} rust/expressions_statements -.-> lab-101055{{"`Your First Rust Lab`"}} end

Hello Rust

This is the source code of the traditional Hello World program.

Create a file called hello.rs:

cd ~/project
touch hello.rs

Add the following code to hello.rs:

// This is a comment, and is ignored by the compiler.
// This is the main function.
fn main() {
    // Statements here are executed when the compiled binary is called.

    // Print text to the console.
    println!("Hello World!");
}

println! is a macro that prints text to the console.

A binary can be generated using the Rust compiler: rustc.

rustc hello.rs

rustc will produce a hello binary that can be executed.

$ ./hello
Hello World!

Activity

Run above to see the expected output. Next, add a new line with a second println! macro so that the output shows:

Hello World!
I'm a Rustacean!

Summary

Coungratulations! You have completed your first LabEx Lab.

If you want to learn more about LabEx and how to use it, you can visit our Support Center . Or you can watch the video to learn more about LabEx.

Programming is a long journey, but Next Lab is just one click away. Let's do it!

Other Rust Tutorials you may like