bots-garden/model-mellumpublic Fork
⑂ main
Commits
⬇ Clone ▾
git clone https://git.rickub.com/bots-garden/model-mellum.git
git clone ssh://git@rickub.com/bots-garden/model-mellum.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Download ZIP
🛟 Updated. 80b3824 · on main · k33g · 2d ago
01-first-rust-prog.md · 59 lines · 1.4 KBmarkdown
Blame HistoryOpen raw

How to Create Your First Rust Program

What the reader will be able to do: Write, compile, and run a simple "Hello, World!" program in Rust.

Prerequisites

  • Rust compiler installed (via rustup)
  • Basic understanding of command-line tools
  • A text editor (e.g., VS Code, vim)

Steps

  1. Install Rust
    If you haven't installed Rust, run:

    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
    

    This installs rustc (the compiler) and cargo (the package manager).

  2. Create a new project
    Run:

    cargo new hello_rust
    cd hello_rust
    

    This creates a directory hello_rust with a basic project structure.

  3. Write the program
    Open src/main.rs in your editor and replace its contents with:

    fn main() {
        println!("Hello, world!");
    }
    
  4. Compile and run
    Run:

    cargo run
    

    Expected output:

    Hello, world!
    
  5. Build the executable
    Run:

    cargo build
    

    This creates a binary in target/debug/hello_rust.

Pitfalls

  • Forgetting to run cargo run instead of rustc directly
  • Not installing Rust via rustup (leads to missing dependencies)
  • Confusing main.rs with lib.rs (use main.rs for executables)

To go further

  • Learn about cargo dependencies in Cargo.toml
  • Explore Rust's ownership model in advanced tutorials
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# How to Create Your First Rust Program

What the reader will be able to do: Write, compile, and run a simple "Hello, World!" program in Rust.

## Prerequisites
- Rust compiler installed (via `rustup`)
- Basic understanding of command-line tools
- A text editor (e.g., VS Code, vim)

## Steps

1. **Install Rust**  
   If you haven't installed Rust, run:
   ```bash
   curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
   ```
   This installs `rustc` (the compiler) and `cargo` (the package manager).

2. **Create a new project**  
   Run:
   ```bash
   cargo new hello_rust
   cd hello_rust
   ```
   This creates a directory `hello_rust` with a basic project structure.

3. **Write the program**  
   Open `src/main.rs` in your editor and replace its contents with:
   ```rust
   fn main() {
       println!("Hello, world!");
   }
   ```

4. **Compile and run**  
   Run:
   ```bash
   cargo run
   ```
   Expected output:
   ```
   Hello, world!
   ```

5. **Build the executable**  
   Run:
   ```bash
   cargo build
   ```
   This creates a binary in `target/debug/hello_rust`.

## Pitfalls
- Forgetting to run `cargo run` instead of `rustc` directly
- Not installing Rust via `rustup` (leads to missing dependencies)
- Confusing `main.rs` with `lib.rs` (use `main.rs` for executables)

## To go further
- Learn about `cargo` dependencies in `Cargo.toml`
- Explore Rust's ownership model in advanced tutorials