Thuta Learning
ရှာဖွေရန်
Rust
BasicProgrammingbeginner

rustup ဖြင့် Rust Install လုပ်ခြင်းနှင့် Cargo Basics

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • rustup ဖြင့် Rust Install လုပ်ခြင်းနှင့် Cargo Basics concept ကို နားလည်ရှင်းပြနိုင်ရန်
  • နမူနာ Rust code ကို ကိုယ်တိုင် run ပြီး output စစ်နိုင်ရန်
  • Tutorial Platform project နှင့် production scenario တွင် မှန်ကန်စွာအသုံးချနိုင်ရန်

နားလည်ထားရမယ့် အချက်

Rust ကို rustup ဆိုတဲ့ toolchain installer တစ်ခုကနေတစ်ဆင့် install လုပ်ရပါတယ်—ဒါက compiler binary ချည်းသာ download ဆွဲတာမဟုတ်ဘဲ update များ, toolchain version များ (stable, beta, nightly), cross-compilation target များအားလုံးကို manage ပေးနိုင်လို့ project တစ်ခုချင်းစီအတွက် Rust version ပြောင်းချင်ရင် reinstall လုပ်စရာ မလိုပါဘူး။ Cargo ဆိုတာ Rust ရဲ့ build tool နှင့် package manager ဖြစ်ပြီး rustup နှင့်အတူ install ဖြစ်လာပါတယ်—project အသစ်ဖန်တီးခြင်း (`cargo new`), compile လုပ်ခြင်း (`cargo build`), run လုပ်ခြင်း (`cargo run`), dependency version fetch/lock လုပ်ခြင်း၊ test run ခြင်းအားလုံးကို handle ပေးပါတယ်—Node.js project က `npm` ကို အားထားသလိုပါပဲ၊ ဒါပေမယ့် compiler build step ကိုပါ built-in ထည့်ထားပါတယ်။ `cargo new` က minimal ဒါပေမယ့် complete project structure တစ်ခု scaffold လုပ်ပေးပါတယ်—package name, version, dependencies ကြေညာထားတဲ့ `Cargo.toml` manifest file နှင့် working "Hello, world!" program ပါတဲ့ `src/main.rs` file။ Cargo မရှိရင် dependency version manually track ရန်, `rustc` ကို flag မှန်အောင်ခေါ်ရန်, build artifact manage ရန် လိုအပ်လာနိုင်ပါတယ်—Cargo ဟာ ဒီ manual bookkeeping ကို ဖယ်ရှားပေးဖို့ ရှိနေတာပါ။ `cargo run` က project ကို compile လုပ်ပြီး (change ရှိရင်) ရလာတဲ့ binary ကို command တစ်ခုတည်းနဲ့ execute လုပ်ပေးလို့ learning ပိုင်းမှာ အမြန်ဆုံး feedback loop ရပါတယ်။

လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်

Tutorial Platform ရဲ့ Rust tooling project (CLI content analyzer, Axum API) များကို Projects chapter မှာ ဆောက်ဖို့အတွက် ဒီ setup ကို local machine ပေါ် ပထမဆုံးအကြိမ် ပြင်ဆင်ရမယ်—rustup install ပြီး `rustc --version`/`cargo --version` ဖြင့် toolchain ရှိမရှိ confirm မယ်။ Project directory တစ်ခုကို `cargo new tutorial-content-tools` ဖြင့် စတင်မယ်—Cargo က `Cargo.toml` နှင့် `src/main.rs` starter file ကို auto-generate ပေးမယ်။ Course တစ်ခုလုံးအတွင်း code example အားလုံးကို `cargo run` ဖြင့် run ကြည့်ပြီး output ကို terminal ထဲ တိုက်ရိုက်စစ်ဆေးမယ်—ဒီလို run ခြင်းကို repeat လုပ်ရင်း Rust compiler ရဲ့ error message တွေကို ဖတ်တတ်လာမှာဖြစ်ပါတယ်။

အတူတူ စမ်းရေးကြည့်မယ်

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

cargo new tutorial-content-tools
cd tutorial-content-tools
cargo run
You should see
Terminal ထဲမှာ "Hello, world!" ပုံနှိပ်ထားသော output ရမည်—Cargo project တစ်ခု အောင်မြင်စွာ compile/run ဖြစ်ကြောင်း သက်သေပြမည်။

၅ မိနစ် စမ်းကြည့်

`cargo new` ဖြင့် project အသစ်တစ်ခု ဖန်တီးပြီး `src/main.rs` ထဲက println! text ကို ပြောင်းပြီး `cargo run` ကို ထပ်ခေါ်ကြည့်ပါ—`cargo build` ကို သီးခြားခေါ်ကြည့်ပြီး `target/` folder ထဲ ဘာဖြစ်လာလဲ observe လုပ်ပါ။

သတိလေးတစ်ချက်

OS package manager (ဥပမာ `apt install rustc`) ကနေ Rust ကို install လုပ်ပြီး rustup ကို ကျော်ခြင်း—version ဟောင်းကျန်နေတတ်ပြီး toolchain switch/update လုပ်ဖို့ ခက်ခဲသွားနိုင်ပါတယ်။

`cargo build` ကို run ပြီးမှ generated binary ကို `target/debug/` ထဲက manually run ဖို့ မေ့ခြင်း (သို့) `cargo run` နှင့် `cargo build` ကို တူညီတဲ့ command လို့ မှားထင်ခြင်း—`cargo run` က compile+execute နှစ်ခုစလုံး တစ်ပြိုင်နက်လုပ်ပေးသည်။

Cargo Book — Getting StartedRust

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • OS package manager (ဥပမာ `apt install rustc`) ကနေ Rust ကို install လုပ်ပြီး rustup ကို ကျော်ခြင်း—version ဟောင်းကျန်နေတတ်ပြီး toolchain switch/update လုပ်ဖို့ ခက်ခဲသွားနိုင်ပါတယ်။
  • `cargo build` ကို run ပြီးမှ generated binary ကို `target/debug/` ထဲက manually run ဖို့ မေ့ခြင်း (သို့) `cargo run` နှင့် `cargo build` ကို တူညီတဲ့ command လို့ မှားထင်ခြင်း—`cargo run` က compile+execute နှစ်ခုစလုံး တစ်ပြိုင်နက်လုပ်ပေးသည်။
  • နမူနာ code ကို production system ပေါ် တိုက်ရိုက်မစမ်းဘဲ local/test environment တွင် အရင်အတည်ပြုပါ။

လေ့ကျင့်ခန်း

`cargo new` ဖြင့် project အသစ်တစ်ခု ဖန်တီးပြီး `src/main.rs` ထဲက println! text ကို ပြောင်းပြီး `cargo run` ကို ထပ်ခေါ်ကြည့်ပါ—`cargo build` ကို သီးခြားခေါ်ကြည့်ပြီး `target/` folder ထဲ ဘာဖြစ်လာလဲ observe လုပ်ပါ။

You'll know it worked when: Terminal ထဲမှာ "Hello, world!" ပုံနှိပ်ထားသော output ရမည်—Cargo project တစ်ခု အောင်မြင်စွာ compile/run ဖြစ်ကြောင်း သက်သေပြမည်။

rustup ဖြင့် Rust Install လုပ်ခြင်းနှင့် Cargo Basics | Thuta Learning