Setup

1️⃣ IDE and tools

  • Rust in Visual Studio Code

  • Rust with Zed

    🎛️ Zed settings that's look like VSCdode
    // Zed settings
    //
    // For information on how to configure Zed, see the Zed
    // documentation: https://zed.dev/docs/configuring-zed
    //
    // To see all of Zed's default settings without changing your
    // custom settings, run the `open default settings` command
    // from the command palette or from `Zed` application menu.
    {
      "active_pane_modifiers": {
        "border_size": 0.0
      },
      "agent_ui_font_size": 12.0,
      "terminal": {
        "font_size": 10.0
      },
      "language_models": {
        "openai_compatible": {
          "GLM": {
            "api_url": "https://api.z.ai/api/coding/paas/v4",
            "available_models": [
              {
                "name": "GLM-4.6",
                "display_name": "GLM 4.6",
                "max_tokens": 200000,
                "max_output_tokens": 32000,
                "max_completion_tokens": 200000,
                "capabilities": {
                  "tools": true,
                  "images": true,
                  "parallel_tool_calls": false,
                  "prompt_cache_key": false
                }
              }
            ]
          },
          "qwen3-vl-30b-a3b-instruct": {
            "api_url": "http://localhost:1234/v1/chat/completions",
            "available_models": [
              {
                "name": "qwen3-vl-30b-a3b-instruct",
                "max_tokens": 100000,
                "max_output_tokens": 32000,
                "max_completion_tokens": 100000,
                "capabilities": {
                  "tools": true,
                  "images": true,
                  "parallel_tool_calls": false,
                  "prompt_cache_key": false
                }
              }
            ]
          }
        }
      },
      "experimental.theme_overrides": {
        "warning.background": "#736e01"
      },
      "show_edit_predictions": false,
      "theme": "Monokai Charcoal (gray)",
      "telemetry": {
        "diagnostics": false,
        "metrics": false
      },
      "ui_font_size": 12.0,
      "buffer_font_size": 11.0,
      "buffer_font_family": "Menlo",
      "agent": {
        "message_editor_min_lines": 8,
        "inline_assistant_model": {
          "provider": "GLM",
          "model": "GLM-4.6"
        },
        "always_allow_tool_actions": true,
        "default_profile": "write",
        "default_model": {
          "provider": "GLM",
          "model": "GLM-4.6"
        }
      },
      "lsp": {
        "rust-analyzer": {
          "initialization_options": {
            "check": {
              "command": "clippy"
            }
          }
        }
      }
    }
    
  • Zed Monokai+Charcoal theme

Install extra tools.👇

cargo install cargo-edit    # 👈 = cargo add, cargo upgrade.
cargo install cargo-watch   # 👈 = cargo watch.
cargo install cargo-audit   # 👈 = cargo audit.

2️⃣ Use Cargo

💡 📦 CargoNPM = Package Manager.

cargo init foo           # 👈 Will init app name `foo`.

cargo run                # 👈 Build and Run.
cargo watch              # 👈 Watch for file change and rebuild.
cargo test               # 👈 Test the tests if has.

cargo build --release    # 👈 No debug = Smaller/Faster.

cargo add tokio          # 👈 add package named `tokio`
cargo rm tokio           # 👈 remove package named `tokio`.

cargo upgrade            # 👈 Upgrade current dependencies.

💡 tokio crate make async easier.

3️⃣ Hello World

👩🏻‍💻 enter cargo init hello-world via command line.

📂 hello-world
├─ 📂 src           # 👈 keep source code in here.
│  └─ 📄 main.rs    # 👈 app entrypoint.
└─ 📦 Cargo.toml

└─ 📄 main.rs

// 👇 main function as an entrypoint.
fn main() {
  // 👇 macro to print something out.
  println!("hello world!"); // 👈 end with ; suffix.
}

└─ 📦 Cargo.toml

[package]
name = "foo"         # 👈 App name.
version = "0.1.0"    # 👈 App version.
edition = "2021"     # 👈 Rust edition.

[dependencies]
tokio = "1.21.2"     # 👈 Added by `cargo add tokio`.

⚡️ You can now skip to 👉 enjoy coding or continue reading 4️⃣ below. 👇


4️⃣ Modules and Project structure.

🤔 What if main.rs has to many codes? Your should separate that concern to each file/folder.

🗂 App + File Module

Separate some function to each file.
📂 foo
├─ 📂 src
│  ├─ 📄 utils.rs    # 👈 module as a file.
│  └─ 📄 main.rs     # 👈 will need utils file.
└─ 📦 Cargo.toml

│ ├─ 📄 utils.rs

pub fn hello() {    // 👈 make it public, or just pub(crate) for internal use.
  println!("hello world!");
}

│ └─ 📄 main.rs

mod utils;          // 👈 include utils file.
use utils;          // 👈 and use it.

fn main () {
  utils::hello();    // 👈 call hello function.
}

Now you have too many files and want to group it into folder as a module. See below how to👇

🗂 App + Folder Module

Group related files to each folder.

See setup4 example

📂 foo
├─ 📂 src
│  │
│  ├─ 📂 utils
│  │  ├─ 📄 mod.rs     # 👈 entrypoint (similar to index.js in JS).
│  │  ├─ 📄 say.rs     # 👈 Contain hello function.
│  │  └─ 📄 cast.rs    # 👈 will able to use say.
│  │
│  └─ 📄 main.rs       # 👈 `mod utils;` then `use utils::say;`
│
└─ 📦 Cargo.toml

│ │ ├─ 📄 mod.rs

pub mod say;        // 👈 import "say" and export.

// 👇 It's look like this in JS.
// export * from say;

│ │ ├─ 📄 say.rs

pub fn hello() {    // 👈 make it public, or just pub(crate) for internal use.
  println!("hello world!");
}

│ │ └─ 📄 cast.rs

use super::say      // 👈 just use. (no mod need because of super)

pub fn cast() {
  say::hello();      // 👈 then call hello function.
}

│ └─ 📄 main.rs

mod utils;          // 👈 include utils file.
use utils::say;     // 👈 and use.

fn main() {
  say::hello();      // 👈 then call hello function.
}

This is better but now you want to reuse that module with other project. Let's make a library then 👇

🗂 Lib

Separate each lib as crate.
cargo init bar --lib
🗂 utils
├─ 📂 src
│  └─ 📄 lib.rs     # 👈 lib entrypoint.
└─ 📦 Cargo.toml

│ └─ 📄 lib.rs

pub fn hello() {    // 👈  make it pub so other can use.
    println!("hello world!");
}

🤔 Now you have 3 options to use it.

  • Push to github and use it like this in Cargo.toml.

    [dependencies]
    foo = { git="https://YOU_GITHUB_REPO_URL"}
    
  • Publish it to the internet and cargo add foo to use it.

  • Use it in Workspace which is the next topic below.👇

🗂 Workspace

aka Monorepo.
📂 workspace-example
│
├─ 🗂 utils
│  ├─ 📂 src
│  │  └─ 📄 lib.rs     # 👈 lib entrypoint.
│  └─ 📦 Cargo.toml    # 1️⃣ utils's cargo.
│
├─ 📂 foo
│  ├─ 📂 src
│  │  └─ 📄 main.rs    # 👈 app entrypoint.
│  └─ 📦 Cargo.toml    # 2️⃣ foo's cargo.
│
└─ 📦 Cargo.toml       # 3️⃣ Workspace's cargo.

│ └─ 📦 Cargo.toml

[dependencies]
utils = { path="../utils" }  # 👈 2️⃣ foo's cargo. refer to utils via path

└─ 📦 Cargo.toml

# 👇 3️⃣ Workspace's cargo.
[workspace]
members = [
  "utils",
  "foo",
]

See worksapce example


Next

Let's continue to Enjoy ➠