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!
fnis used to define a function in Rust.main()function is an important one from where the execution starts from.println!()is a macro that will print hello, world in terminal with newline at the end.!afterprintln!()means it is a macro and not a function.- 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).
- Semicolon is required to terminate the statement.
Labels: rust