// Rust doesn't have
// multiline comments
// -\(oo)/-
fn main ()
{
println! ("Hello World!"); // This is a comment
println! ("{}", "This is a text strings
spread through multiple lines");
}Rust is another relatively recent compiled language. Source files in
Rust use the .rs extension.
Rust is quite similar to C/C++, in the way of terminating
instructions and grouping them, using the ; as a separator
and the {} for grouping instructions. It also requires the
definition of a main function to indicate the start of the
program and uses single-line comments like C++, not being able to write
multi-line comments.
DID YOU KNOW…
Rust was the first language, in addition to C and assembly, to be supported for the development of the Linux kernel. Google also announced support for Rust within its Open Source Android project, as an alternative to C/C++. The infamous Microsoft is also considering the language to rewrite parts of the main Windows libraries.
The language handles multi-line strings without problems.
The macro println! (macros in Rust are identified with a
! character at the end of the name) prints adding a
carriage return. As you can imagine, there is another macro called
print! that doesn’t add the carriage return.
To compile and execute our program we will use the commands:
$ rustc hello
$ ./hello
The language presents itself as an improved alternative to C/C++, offering similar performance with more modern features such as type safety, avoiding the need to use a garbage collector, and concurrency.
I’M A NEWBIE…
println!is not a function but a macro that simplifies printing strings to standard output. This macro is converted into specific code during the compilation process. So, it’s a macro.
Rust was born as a personal project by Graydon Hoare while working for Mozilla in 2006. The name of the language seems to come from a family of fungi… The project was sponsored by Mozilla in 2009 and officially announced in 2010, but it wasn’t until 2012 that the first pre-alpha version was released, and version 1.0 didn’t arrive until 2015. That said, from version 1, new features are added in 6-week cycles.
Rust is one of the youngest languages we’ll be using.
Rust offers its own installation system. You can follow the official page for details; however, most distributions offer their own packages. For Debian distributions, you can install it with the following command:
apt install rustc
Summary
- Compiled language
- Extension:
rs - Line terminator:
; - Groups instructions with:
{ instructions } - Multi-line comments: Not supported
- Single-line comments:
// - String delimiter:
"string" - You can print text with
println!(Adds carriage return) - Supports multi-line strings: Naturally supported
- Does not Support
HERE-DOCS - Entry Point: Function
main