Truy cập
Thông tin đăng nhập:
- Người dùng:
ferris - Mật khẩu: (được lưu trữ trong
/root/.cloudzy-creds)
SSH vào server với quyền root, sau đó chuyển sang người dùng Rust:
su - ferris
Các Thư Mục Quan Trọng
/home/ferris/.cargo/→ Các tệp nhị phân Cargo (cargo, các crate đã cài đặt)/home/ferris/.rustup/→ Toolchain & các thành phần Rust/home/ferris/→ Workspace của bạn (các project đặt ở đây)
Các Lệnh Hữu Ích
Xác minh cài đặt:
cargo --version
rustc --version
Cập nhật Rust:
rustup update
Thêm/Cập nhật công cụ bổ sung (ví dụ: linter):
rustup component add clippy
Gỡ cài đặt Rust:
rustup self uninstall
Build project của bạn:
cargo build
Chạy project của bạn:
cargo run
Chạy kiểm tra:
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).
Chỉnh sửa 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();
}
Chạy nó:
cargo run