'Hello, world' Rust

Author: Jase Batchelor

‘Hello, world’ with Rust

In the previous section we installed Rust using the rustup command, and verified that cargo and rustc are now available on our system.

We will now create a traditional ‘Hello, world’ application before moving on to somewhat more useful examples ;)

Open your terminal and type the following command:

cargo new hello-world
# Created binary (application) `hello-world` package

Now change to the newly created hello-world directory

cd hello-world

cargo run
#   Compiling hello-world v0.1.0 (/Users/jase/hello-world)
#     Finished dev [unoptimized + debuginfo] target(s) in 0.61s
#      Running `target/debug/hello-world`
# Hello, world!

That’s it!! The cargo command has generated a Rust application with the default structure.

image

The default project layout created by Cargo is detailed here: https://doc.rust-lang.org/cargo/guide/project-layout.html

image

If you would like more information check out the Cargo documentation at https://doc.rust-lang.org/cargo/

In the next section we will installing some add-ons that are useful in daily development, and in the course of the Axum tutorial you will see more advanced commands.