Labs ICT
โญ Pro Login

Hello, World!

Your first Rust program and how cargo works.

Hello World

Every programming journey starts with a "Hello, World!" program. In Rust, the main function is the entry point of your program. You'll notice that the println! macro has an exclamation mark at the end. This tells Rust that it's a macro rather than a regular function.

When writing functions in Rust, you use the fn keyword. The semicolons in Rust are important and actually matter. If you forget a semicolon where one is expected, you'll get a compiler error. This is different from some other languages where semicolons are optional.

To run your Rust program, you have a couple of options. You can use cargo build to compile your code and then run the resulting executable. Or you can simply use cargo run which will both compile and run your program in one step. The Cargo.toml file is where your project configuration lives.

// The main function is where your program starts
fn main() {
    // println! is a macro (notice the !)
    println!("Hello, World!");
    
    // Semicolons are required at the end of statements
    let message = "Welcome to Rust";
    println!("{}", message);
}
Try it Yourself ->

๐Ÿงช Quick Quiz

What is the entry point function in Rust?