Access
Credentials:
- User:
ferris - Password: (stored in
/root/.cloudzy-creds)
SSH vào server với quyền root, sau đó chuyển sang người dùng Rust:
su - ferris
Important Directories
/home/ferris/.cargo/→ Cargo binaries (cargo, installed crates)/home/ferris/.rustup/→ Toolchain & các thành phần Rust/home/ferris/→ Workspace của bạn (các project đặt ở đây)
Useful Commands
Verify installation:
cargo --version
rustc --version
Update Rust:
rustup update
Thêm/Cập nhật công cụ bổ sung (ví dụ: linter):
rustup component add clippy
Uninstall Rust:
rustup self uninstall
Build project của bạn:
cargo build
Chạy project của bạn:
cargo run
Run tests:
cargo test
Build tài liệu cho project của bạn:
cargo doc --open
Xuất bản thư viện lên crates.io:
cargo publish
Một Ứng Dụng Rust Nhỏ
Tạo dự án mới:
cargo new hello-rust
cd hello-rust
Chạy chương trình mặc định:
cargo run
Thêm dependency qua CLI:
cargo add ferris-says
Sau đó build (Cargo sẽ tự cài dependency cho bạn):
cargo build
Lệnh này cũng sẽ tạo ra Cargo.lock (file khóa phiên bản dependency).
Edit src/main.rs:
use ferris_says::say;
use std::io::{stdout, BufWriter};
fn main() {
let stdout = stdout();
let message = String::from("Hello fellow Rustaceans!");
let width = message.chars().count();
let mut writer = BufWriter::new(stdout.lock());
say(&message, width, &mut writer).unwrap();
}
Run it:
cargo run