init

First, create a program template in rust.

mkdir -p ~/rust
cd ~/rust
cargo init
.
├── Cargo.toml
└── src
    └── main.rs

You can create these files yourself or with init.

Cargo.toml

[package]
name = "rust"
version = "0.1.0"
edition = "2021"

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

[dependencies]

src/main.rs

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

editor

Next, let's check the contents of the program.

To check, use editor (editor). I use vim, but I would recommend visual studio.

brew install vim
vim src/main.rs

src/main.rs

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

This is a program that outputs the string `hello world!

build

You can build this src and convert it to binary, i.e., the app itself, so that you can run it on that computer.

cargo build

target/debug/rust

target
└── debug
    ├── rust ← binary
    └── rust.d

rust is a very good language because it is one-binary, meaning that the compiled result is a single file.

$ ./target/debug/rust
Hello, world!

results matching ""

    No results matching ""