LogoDuyệtSr. Data Engineer
HomeAboutPhotosInsightsCV

Footer

Logo

Resources

  • Rust Tiếng Việt
  • /archives
  • /series
  • /tags
  • Status

me@duyet.net

  • About
  • LinkedIn
  • Resume
  • Projects

© 2026 duyet.net | Sr. Data Engineer

Rust: cargo-edit

Note: This post is over 5 years old. The information may be outdated.

Chuỗi bài viết Rust Tiếng Việt là một trong những nội dung nằm trong sách Rust Tiếng Việt

cargo-edit là công cụ mở rộng của cargo cho phép có thêm một số tính năng quản lý dependencies giống như npm hoặc yarn.

Ví dụ như  cargo add sẽ hoạt động giống npm installhoặc yarn để cài packages, thay vì edit Cargo.toml thủ công như trước đây (trong Rust "packages" được gọi là "crates").

Một số lệnh mà cargo-edit hỗ trợ là:

  • cargo install: hoạt động giống như npm install -g hoặc yarn global add
  • cargo add: thêm vào Cargo.toml crate mà bạn cần. Ta vẫn sẽ cần chạy cargo build hoặc cargo check để download và compile dependencies.
  • cargo rm: ngược lại xóa dependencies ra khỏi Cargo.toml.
  • cargo upgrade: upgrade dependencies phiên bản mới nhất.
  • cargo set-version: thay đổi thuộc tính version trong Cargo.toml

Cài đặt

Để cài đặt cargo-edit cho OS của bạn, hãy tham khảo tại đây.

$ cargo install cargo-edit

Ví dụ

cargo add

Thêm một dependencies mới vào Cargo.toml. Nếu không chỉ định version, cargo add sẽ tự lấy version mới nhất từ crates.io.

$ # Có version cụ thể
$ cargo add regex@0.1.41
$ # Thêm vào devDependency
$ cargo add regex --dev
$ # Tự lấy version từ [crates.io](http://crates.io) và thêm vào build dependency
$ cargo add gcc --build
$ # non-crates.io crate
$ cargo add local_experiment --path=lib/trial-and-error/
$ # non-crates.io crate; tự động tìm tên của crate đó
$ cargo add lib/trial-and-error/
$ # Features
$ cargo add clap --features derive

cargo rm

Ngược lại với add

$ # Remove a dependency
$ cargo rm regex
$ # Remove a development dependency
$ cargo rm regex --dev
$ # Remove a build dependency
$ cargo rm regex --build

cargo set-version

# Set the version to the version 1.0.0
$ cargo set-version 1.0.0
# Bump the version to the next major
$ cargo set-version --bump major
# Bump version to the next minor
$ cargo set-version --bump minor
# Bump version to the next patch
$ cargo set-version --bump patch
Feb 6, 2022·4 years ago
|Rust|
RustVietnameseRust Tiếng Việt
|Edit|

Related Posts

Rust: indoc

indoc là một crate nhỏ nhưng hữu ích giúp canh lề (indented documents). indoc!() macro nhận multiline string và un-indents lúc compile time, xoá tất cả khoảng trắng đầu tiên trên cách dòng dựa theo dòng đầu tiên.

Aug 6, 2022·4 years ago
Read more

Rust: Rayon - A data parallelism library for Rust

rayon là thư viện data-parallelism cho Rust, gọn nhẹ và dễ dàng convert từ code tính toán tuần tự sang song song mà vẫn đảm bảo không lỗi data-race.

Aug 6, 2022·4 years ago
Read more

Rust: Box

Tất cả giá trị trên Rust mặc định đều được allocated trên stack. Giá trị có thể được boxed, allocated trên heap bằng cách sử dụng Box<T>. Box<T> là một smart pointer của Rust cho phép allocated trên heap giá trị có kiểu T, còn pointer trỏ đến giá trị đó sẽ nằm trên stack.

Mar 5, 2022·4 years ago
Read more

Rust Design Pattern: Builder Pattern

Builder được sử dụng cực kỳ phổ biến trong Rust so với các ngôn ngữ khác, bởi vì Rust không có overloading.

Feb 13, 2022·4 years ago
Read more
On this page
  • Ví dụ
  • cargo add
  • cargo rm
  • cargo set-version
On this page
  • Ví dụ
  • cargo add
  • cargo rm
  • cargo set-version