Writing Hello World in Rust

By TechCogs | Programming and Coding | 26 Feb 2020


Rust is a newer programming language that's growing in popularity.  While it has some similarities to languages like C++ and Go it's very much its own thing with its own syntax.  Despite that, writing the classic Hello World program in Rust is fairly easy and straightforward.

fn main() {
println!("Hello, World!");
}

That's all there is to it.

The "fn" identifier denotes the beginning of a function.  The code layout uses curly braces and semi-colons just like C++-style languages.  The exclamation point in the call to "println" let's you know that println is a macro, and the data following it is sent to the macro.  The D programming language also uses exclamation points in similar ways for templates.

Where Rust really differs from C++-style programs is in how functions are written, which is more like Go, and how variables are managed, with a heavy emphasis on variable ownership and borrowing and things like that.  Those subjects are worthy of an article dedicated just to them.

As long as you have the Rust compiler installed the above code will get you started.  For more information take a look at rust-lang.org.

How do you rate this article?

6


TechCogs
TechCogs

I work with Linux, technology, computers, and science.


Programming and Coding
Programming and Coding

The wonderful world of software engineering and software creation, centered around languages like D, Java, Python, Dart, and C++.

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.