Skip to content

Hello world (Rust)

Posted on:January 5, 2024 at 08:00 AM (1 min read)

Table of contents

Open Table of contents

Create an application

To create an app with Cargo, using cargo init <app-name> on CLI

cargo init hello-world

This will populated a following boilerplate for hello-world app.

📁 hello-world
├─📁 src           # source code here
│ └─ main.rs
└─ 📦 Cargo.toml    # package definition

main.rs

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

Cargo.toml

[package]
name = "hello-world"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

Run your first hello world

cargo run
   Compiling hello-world v0.1.0 (.../src/public/learns/rust/hello-world/hello-world)
    Finished dev [unoptimized + debuginfo] target(s) in 0.72s
     Running `target/debug/hello-world`
Hello, world!