Learning Rust Pt. 2

Wednesday, January 25, 2023 | Permalink

Rust files are normally identifies via .rs extension. A journey with programming language should always starts with hello, world program and here is the Rust's one in hello.rs.

fn main() {
  println!("hello, world");
}

Being a compiled programming language, we need to invoke a Rust compiler or rustc on this program.

$ rustc hello.rs

Compile will create an executable (if error not found) usually named after the program file without extension that is easily run!

$ ./hello
hello, world

And there you have the hello, world!


  1. fn is used to define a function in Rust.
  2. main() function is an important one from where the execution starts from.
  3. println!() is a macro that will print hello, world in terminal with newline at the end.
  4. ! after println!() means it is a macro and not a function.
  5. You don't have to worry about the difference between macro and function for now (If you're still insisting, here is one answer from StackOverflow might helpful for you).
  6. Semicolon is required to terminate the statement.

Labels: